Creating a block-based theme Category page template for Custom Post Types

I’ve been experimenting with building block-based themes. In order to create a category page template you would create a /block-template directory and add a category.html file. Then you can jump into the block editor, drop in whatever blocks you want to use, go to the code editor, copy the code and paste that into the category.html file.

Now, the key to all of this is that one of the blocks you use when creating the template is the core Query loop block. You’ll then set it to ‘Inherit query from URL’:

That’s it, you’ve got a category page template that displays the posts of whatever category the current url is showing.

The category page template doesn’t work for Custom Post Types

That’s right, I tried using the core Query loop block, but the categories of the custom post type would not display.

Why is that? Because custom post types are excluded from the main query by default. Thank you Pieter Goosen for your very helpful StackOverflow assist.

At any rate, to include the custom post type in the main query, you just need to use the pre_get_posts hook, here’s a code snippet of what that could look like straight from Pieter’s StackOverflow:

function custom_post_type_cat_filter($query) {
  if ( !is_admin() && $query->is_main_query() ) {
    if ($query->is_category()) {
      $query->set( 'post_type', array( 'post', 'YOUR CPT' ) );
    }
  }
}

add_action('pre_get_posts','custom_post_type_cat_filter');

385 thoughts on “Creating a block-based theme Category page template for Custom Post Types

  1. Pingback: Google
  2. Pingback: nubain
  3. Pingback: free app for pc
  4. Pingback: cellislim
  5. Pingback: Herbal Incense
  6. Pingback: clitoral vibrator
  7. Pingback: cosmetic box
  8. Pingback: golden bullet
  9. Pingback: pc reparatur jona
  10. Pingback: learn more
  11. Pingback: Cake carts
  12. Pingback: car recycling
  13. Pingback: CZ Shadow 2
  14. Pingback: BERETTA 92X
  15. Pingback: meritroyalbet
  16. Pingback: meritroyalbet
  17. Pingback: meritking
  18. Pingback: madritbet
  19. Pingback: eurocasino
  20. Pingback: madridbet
  21. Pingback: elexusbet
  22. Pingback: Eatery Nanaimo
  23. Pingback: cock sleeves
  24. Pingback: stock market drop
  25. Pingback: anita
  26. Pingback: eurocasino
  27. Pingback: scrap car removal
  28. Pingback: listen here
  29. Pingback: shrooms chocolate
  30. Pingback: Haupia strain
  31. Pingback: Watermelon haupia
  32. Pingback: Platinum haupia
  33. Pingback: Bubble hash
  34. Pingback: Moroccan hash
  35. Pingback: Litto
  36. Pingback: Bubble hash
  37. Pingback: meritroyalbet
  38. Pingback: eurocasino
  39. Pingback: bahis siteleri
  40. Pingback: meritking
  41. Pingback: meritking
  42. Pingback: grandpashabet
  43. Pingback: Grandpashabet
  44. Pingback: fuck google
  45. Pingback: fuck google
  46. Pingback: madridbet
  47. Pingback: meritking
  48. Pingback: fuck google
  49. Pingback: grandpashabet
  50. Pingback: child porn
  51. Pingback: porn
  52. Pingback: grandpashabet
  53. Pingback: izmir escort
  54. Pingback: porn
  55. Pingback: sms onay
  56. Pingback: steroid satın al
  57. Pingback: steroid satın al
  58. Pingback: child porn
  59. Pingback: fuck google
  60. Pingback: ozempic
  61. Pingback: hacklink
  62. Pingback: xxlargeseodigi
  63. Pingback: porn
  64. Pingback: Est P Boot
  65. Pingback: Er best
  66. Pingback: porn
  67. Pingback: BoostGrams
  68. Pingback: çeşme transfer
  69. Pingback: buy an essay cheap
  70. Pingback: rutgers essay help
  71. Pingback: order cheap essay
  72. Pingback: Desyrel
  73. Pingback: 25 mg viagra
  74. Pingback: Diyet Yolu
  75. Pingback: gezginizm
  76. Pingback: gezginizm
  77. Pingback: Moda Danışmanı
  78. Pingback: Yeni Başlayanlar
  79. Pingback: Yeni Başlayanlar
  80. Pingback: Opel Oto Çıkma
  81. Pingback: Blog
  82. Pingback: hd porno izle
  83. Pingback: Adalat
  84. Pingback: izmir travesti
  85. Pingback: porno
  86. Pingback: izmir travesti
  87. Pingback: tadalafil 5mg tab
  88. Pingback: cialis dapoxetine
  89. Pingback: Porn
  90. Pingback: tamoxifen muscles
  91. Pingback: lisinopril nmr
  92. Pingback: metformin fiyati
  93. Pingback: yasam ayavefe
  94. Pingback: kralbet
  95. Pingback: sikis
  96. Pingback: sms onay
  97. Pingback: ativan and lexapro
  98. Pingback: steroid
  99. Pingback: sms onay
  100. Pingback: steroid satın al
  101. Pingback: grandpashabet
  102. Pingback: cephalexin in dogs
  103. Pingback: grandpashabet
  104. Pingback: child porn
  105. Pingback: forum
  106. Pingback: contrave diet plan
  107. Pingback: cozaar arb
  108. Pingback: depakote dosing
  109. Pingback: casino porna
  110. Pingback: sigarpu
  111. Pingback: child porn
  112. Pingback: actos psoriasis
  113. Pingback: robaxin wikipedia
  114. Pingback: ricnirpaelt
  115. Pingback: anal porn
  116. Pingback: acarbose time
  117. Pingback: Kod Bulutu
  118. Pingback: Poliçe Paneli
  119. Pingback: child porn
  120. Pingback: child porn
  121. Pingback: child porn
  122. Pingback: viagra in europe
  123. Pingback: tadalafil pills
  124. Pingback: jojobet
  125. Pingback: jojobet twitter
  126. Pingback: link
  127. Pingback: Porno
  128. Pingback: Porno
  129. Pingback: ananın amı
  130. Pingback: child porn
  131. Pingback: meritking
  132. Pingback: child porn
  133. Pingback: child porn
  134. Pingback: child porn
  135. Pingback: anal porn
  136. Pingback: spinco
  137. Pingback: iyibilirdik
  138. Pingback: porn
  139. Pingback: meritking
  140. Pingback: casino porna
  141. Pingback: Cocuk pornosu
  142. Pingback: child porn
  143. Pingback: child porn
  144. Pingback: child porn
  145. Pingback: porn
  146. Pingback: bursa travesti
  147. Pingback: sex
  148. Pingback: porn
  149. Pingback: sex historie
  150. Pingback: Mehmetin köpeği
  151. Pingback: Mehmetin köpeği
  152. Pingback: hardcore porn
  153. Pingback: fuck
  154. Pingback: child porn
  155. Pingback: child porn
  156. Pingback: bmw
  157. Pingback: kadinlar
  158. Pingback: sex
  159. Pingback: spam
  160. Pingback: porn
  161. Pingback: bugatti tumblr
  162. Pingback: istanbul travesti
  163. Pingback: ankara travesti
  164. Pingback: edebiyat tumblr
  165. Pingback: ankaratravesti.xyz
  166. Pingback: porn
  167. Pingback: child porn
  168. Pingback: child porn
  169. Pingback: child porn
  170. Pingback: iporn
  171. Pingback: porn
  172. Pingback: porn
  173. Pingback: child porn
  174. Pingback: porn
  175. Pingback: meritking
  176. Pingback: meritking
  177. Pingback: meritking
  178. Pingback: meritking
  179. Pingback: rize tumblr
  180. Pingback: spam
  181. Pingback: gece tumblr
  182. Pingback: sakakrizi tumblr
  183. Pingback: child porn
  184. Pingback: inovapin.com
  185. Pingback: porn
  186. Pingback: Konya SEO Uzmanı
  187. Pingback: porn
  188. Pingback: spam
  189. Pingback: porn
  190. Pingback: child porn
  191. Pingback: child porn
  192. Pingback: child porn
  193. Pingback: child porn
  194. Pingback: child porn
  195. Pingback: child porn
  196. Pingback: porn
  197. Pingback: ankara psikolog

Comments are closed.