{"id":60604,"date":"2023-07-28T17:32:29","date_gmt":"2023-07-28T15:32:29","guid":{"rendered":"https:\/\/jesusyesares.com\/?p=60604"},"modified":"2026-11-27T18:22:36","modified_gmt":"2026-11-27T17:22:36","slug":"how-to-create-a-custom-loop-in-wordpress","status":"publish","type":"post","link":"https:\/\/jesusyesares.com\/en\/web-seo\/how-to-create-a-custom-loop-in-wordpress\/","title":{"rendered":"How to create a custom loop in WordPress"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I&#8217;ve often been asked how to show a <strong>custom loop in WordPress<\/strong>, for example <strong>for a specific category<\/strong>. And it&#8217;s no trivial matter. If you like to control what&#8217;s shown on screen, my recommendation is <strong>not to leave that job to WordPress archives<\/strong>, but to do it yourself, customizing the list of posts you want to show at each URL.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">When should we show a custom loop?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you have a simple blog and don&#8217;t worry much about information architecture, this isn&#8217;t the post for you. But <strong>if you want to control what you&#8217;re showing on each page<\/strong>, stick around.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By the way, in this post <strong>I&#8217;ll only focus on how to show the list of posts<\/strong>. We can show this list for a specific blog category, for example, on a specific WordPress page. This is very useful, for instance, when creating a <strong>silo architecture<\/strong> on your site.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you don&#8217;t know what a silo architecture is or how to organize one in WordPress, let me know in the comments and I&#8217;ll be happy to write a post specifically on the subject.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I&#8217;ll also talk about <strong>custom post types<\/strong> and <strong>taxonomies<\/strong>. If you don&#8217;t know what they are, I also invite you to tell me in the comments below.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What exactly do we want to do?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Imagine you have a website where you write about gadgets and electronic devices. You want to split each type of device you write about on the blog into separate pages.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On the other hand, imagine you have these posts organized in a custom post type (CPT) called <em>Devices<\/em>. We&#8217;ve created a category-style taxonomy for this CPT, with three different categories:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em>Computers<\/em><\/li>\n\n\n\n<li><em>Phones<\/em><\/li>\n\n\n\n<li><em>Tablets<\/em><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>What we want is to show the list of posts written under that CPT for each category on a different page<\/strong>. That is, we want a <code>\/computers\/<\/code> page, a <code>\/phones\/<\/code> page and a <code>\/tablets\/<\/code> page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To do this we&#8217;ll create those three blank pages and show the query loop with blocks, without touching a single line of code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How do we show a loop on a WordPress page with blocks?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The most convenient way to do this is, indeed, with blocks. In fact, <strong>WordPress has a native Query Loop block<\/strong>, which is a bit limited.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So <strong>I&#8217;m going to use a plugin I&#8217;m a big fan of: <a href=\"https:\/\/wordpress.org\/plugins\/generateblocks\/\" class=\"ek-link\">GenerateBlocks<\/a><\/strong>. This plugin is very simple, with just <strong>four or five basic blocks<\/strong>, but they have loads of options and let you customize everything very well. In fact, the <a aria-label=\"GenerateBlocks Pro (opens in a new tab)\" href=\"https:\/\/jesusyesares.com\/en\/?campaign=articgb&amp;ref=188\" target=\"_blank\" rel=\"noreferrer noopener nofollow sponsored\" class=\"ek-link\">GenerateBlocks Pro<\/a> service, created by the GeneratePress team, is built entirely on the free plugin, which you can find in the <a aria-label=\" (opens in a new tab)\" href=\"https:\/\/wordpress.org\/plugins\/generateblocks\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\">WordPress plugin directory<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To get to the point, imagine we&#8217;re on the blank <em>Phones<\/em> page, one of the categories of the <em>Devices<\/em> CPT. First we&#8217;ll insert a <strong>Container<\/strong> block, which gives us more control over the design.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"490\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" src=\"http:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/contenedor-generateblocks-1024x490.webp\" alt=\"Container block in generateblocks\" class=\"wp-image-40165\" srcset=\"https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/contenedor-generateblocks-1024x490.webp 1024w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/contenedor-generateblocks-300x144.webp 300w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/contenedor-generateblocks-768x367.webp 768w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/contenedor-generateblocks.webp 1200w\" fetchpriority=\"high\" \/><figcaption class=\"wp-element-caption\">GenerateBlocks Container block<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Once the container is inserted, inside it we&#8217;ll insert the Query Loop block, but be careful not to pick the wrong one: <strong>we&#8217;ll use the GenerateBlocks one, which is blue<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1011\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" src=\"http:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/insertar-loop-generateblocks-1024x1011.webp\" alt=\"GenerateBlocks Query Loop block\" class=\"wp-image-40168\" srcset=\"https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/insertar-loop-generateblocks-1024x1011.webp 1024w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/insertar-loop-generateblocks-300x296.webp 300w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/insertar-loop-generateblocks-768x758.webp 768w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/insertar-loop-generateblocks.webp 1102w\" fetchpriority=\"low\" \/><figcaption class=\"wp-element-caption\">GenerateBlocks Query Loop block.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When we insert it, it asks us to choose the <strong>type of layout<\/strong> we want. I&#8217;ll choose, for example, <em>Two columns with featured image<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"563\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" src=\"http:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/estilos-loop-de-generateblocks-1024x563.webp\" alt=\"Layouts for the query block offered by generateblocks\" class=\"wp-image-40167\" srcset=\"https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/estilos-loop-de-generateblocks-1024x563.webp 1024w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/estilos-loop-de-generateblocks-300x165.webp 300w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/estilos-loop-de-generateblocks-768x422.webp 768w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/estilos-loop-de-generateblocks.webp 1200w\" fetchpriority=\"low\" \/><figcaption class=\"wp-element-caption\">Loop styles available in GenerateBlocks.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">By the way, keep in mind that <strong>this tool lets us compose whatever layout we want, since it&#8217;s about nesting blocks inside one another<\/strong>. This is incredibly powerful because, with a little design knowledge and some experience handling blocks, you can create anything you like.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now we need to tell this loop, or Query Loop, what we want to show. To do this, we go to the <strong>block settings<\/strong> (make sure you&#8217;re on the query block, not on one of the inner blocks) in the block settings panel that appears on the right in WordPress. You should see something like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"912\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" src=\"http:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/elegir-cpt-mostrar-loop-generateblocks.webp\" alt=\"Choosing the cpt to show \nin the generateblocks query loop\" class=\"wp-image-40166\" srcset=\"https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/elegir-cpt-mostrar-loop-generateblocks.webp 600w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/elegir-cpt-mostrar-loop-generateblocks-197x300.webp 197w\" fetchpriority=\"low\" \/><figcaption class=\"wp-element-caption\">List of post types we can show in the GenerateBlocks loop.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Here we can see the <strong>list of post types<\/strong> we have in WordPress. Normally there will be <strong>Posts and Pages<\/strong> and, if we&#8217;ve already created the <em>Devices<\/em> custom post type, it will be in the list too.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In our case, I&#8217;ll select <em>Devices<\/em>, which is what I want to show, and click the Add parameter button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"582\" height=\"1024\" sizes=\"auto, (max-width: 582px) 100vw, 582px\" src=\"http:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/taxonomia-cpt-loop-generateblocks-582x1024.webp\" alt=\"Types of filters you can apply in the GenerateBlocks query loop\" class=\"wp-image-40171\" srcset=\"https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/taxonomia-cpt-loop-generateblocks-582x1024.webp 582w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/taxonomia-cpt-loop-generateblocks-171x300.webp 171w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/taxonomia-cpt-loop-generateblocks.webp 600w\" fetchpriority=\"low\" \/><figcaption class=\"wp-element-caption\">Parameters available in the GenerateBlocks query loop block<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The list here is long, since <strong>we can filter by loads of parameters<\/strong>. I won&#8217;t go through them all; if you&#8217;d like me to cover them, just let me know in the comments.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In my case, I&#8217;ll select <strong>Taxonomies<\/strong>, since I want to select a specific category. As you can see, besides categories and tags, there&#8217;s also device types, the taxonomy I created specifically for <em>Devices<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"335\" height=\"270\" sizes=\"auto, (max-width: 335px) 100vw, 335px\" src=\"http:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/insertar-taxonomia-loop-generateblocks.webp\" alt=\"Choosing the taxonomy to show in generateblocks\" class=\"wp-image-40169\" srcset=\"https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/insertar-taxonomia-loop-generateblocks.webp 335w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/insertar-taxonomia-loop-generateblocks-300x242.webp 300w\" fetchpriority=\"low\" \/><figcaption class=\"wp-element-caption\">Taxonomies available in WordPress.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When we select the <em>Device types<\/em> taxonomy, we can then choose the specific category of this taxonomy that we want to show, picking from the three types we mentioned at the start.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"688\" height=\"686\" sizes=\"auto, (max-width: 688px) 100vw, 688px\" src=\"http:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/taxonomia-concreta-bucle-de-entradas-generateblocks.webp\" alt=\"Selecting the specific category for the custom loop.\" class=\"wp-image-40170\" srcset=\"https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/taxonomia-concreta-bucle-de-entradas-generateblocks.webp 688w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/taxonomia-concreta-bucle-de-entradas-generateblocks-150x150.webp 150w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/taxonomia-concreta-bucle-de-entradas-generateblocks-300x300.webp 300w\" fetchpriority=\"low\" \/><figcaption class=\"wp-element-caption\">Categories of the Device types taxonomy.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Since we&#8217;re on the phones page, I&#8217;ll select the <em>Phones<\/em> category.<\/p>\n\n\n\n<figure class=\"wp-block-image alignright size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"328\" height=\"92\" sizes=\"auto, (max-width: 328px) 100vw, 328px\" src=\"http:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/url-pagina-donde-mostrar-el-loop.webp\" alt=\"url of the page where we'll show the custom loop in WordPress\" class=\"wp-image-40173\" srcset=\"https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/url-pagina-donde-mostrar-el-loop.webp 328w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/url-pagina-donde-mostrar-el-loop-300x84.webp 300w\" fetchpriority=\"low\" \/><figcaption class=\"wp-element-caption\">URL of the page where we&#8217;ll show all the posts about phones.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">And that&#8217;s it. When we preview the page, we&#8217;ll see that its URL is <code>\/phones\/<\/code>, and that we can open each of the posts about phones we&#8217;ve written.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">What&#8217;s more, when we open each of these posts, we&#8217;ll see that the URL sits under <code>\/device\/<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"684\" height=\"84\" sizes=\"auto, (max-width: 684px) 100vw, 684px\" src=\"http:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/url-articulo-dentro-categoria.webp\" alt=\"url of the post inside the device category\" class=\"wp-image-40172\" srcset=\"https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/url-articulo-dentro-categoria.webp 684w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/url-articulo-dentro-categoria-300x37.webp 300w\" fetchpriority=\"low\" \/><figcaption class=\"wp-element-caption\">URL of a post inside the phones category.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This could be improved a lot, since we could make <code>\/phones\/<\/code> better organized as <code>\/devices\/phones\/<\/code>, creating a better structure. But we&#8217;ll leave that for a post about how to organize a silo structure.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The point is that we finally have our page <strong>showing only the posts from the <em>Devices<\/em> CPT<\/strong> that belong to the <em>Phones<\/em> category (<em>Device type<\/em>), as you can see below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1152\" height=\"2560\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" src=\"http:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/pagina-moviles-completa-hecha-con-generate-blocks-scaled.webp\" alt=\"complete phones page built with the generate blocks custom post loop\" class=\"wp-image-40174\" srcset=\"https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/pagina-moviles-completa-hecha-con-generate-blocks-scaled.webp 1152w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/pagina-moviles-completa-hecha-con-generate-blocks-768x1706.webp 768w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/pagina-moviles-completa-hecha-con-generate-blocks-135x300.webp 135w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/pagina-moviles-completa-hecha-con-generate-blocks-461x1024.webp 461w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/pagina-moviles-completa-hecha-con-generate-blocks-691x1536.webp 691w, https:\/\/jesusyesares.com\/wp-content\/uploads\/2023\/07\/pagina-moviles-completa-hecha-con-generate-blocks-922x2048.webp 922w\" fetchpriority=\"low\" \/><figcaption class=\"wp-element-caption\">The complete Phones page, showing all the posts in the Device type taxonomy and the Phones category.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">I hope you liked it. I&#8217;d love to hear from you in the comments: tell me what you think is missing from this tutorial or what you&#8217;d like me to explain.<\/p>\n<span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:329,&quot;href&quot;:&quot;https:\\\/\\\/wordpress.org\\\/plugins\\\/generateblocks&quot;,&quot;archived_href&quot;:&quot;https:\\\/\\\/web-wp.archive.org\\\/web\\\/20260901074529\\\/https:\\\/\\\/wordpress.org\\\/plugins\\\/generateblocks\\\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-11-27 17:24:14&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-11-27T17:24:14+00:00&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]\"><\/span>","protected":false},"excerpt":{"rendered":"<p>In this post I explain how to show all the posts in a given category on a page using a custom GenerateBlocks query loop.<\/p>\n","protected":false},"author":2,"featured_media":60615,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_ayudawp_aiss_exclude":false,"_ayudawp_aiss_exclude_summary":false,"_ayudawp_aiss_summary":"I've often been asked how to show a custom loop in WordPress, for example for a specific category. We can show this list for a specific blog category, for example, on a specific WordPress page. How do we show a loop on a WordPress page with blocks?.","_ayudawp_aiss_summary_provider":"extractive","_ayudawp_aiss_summary_hash":"8aa2356f5f34ee6ec68cbffb0d94aa4e735616e4","_native_aeo_pack_title":"How to create a custom loop in WordPress","_native_aeo_pack_description":"How to show all the posts in a given category on a page using the WordPress loop.","_native_aeo_pack_og_title":"","_native_aeo_pack_og_description":"","_native_aeo_pack_canonical":"","_native_aeo_pack_og_image":null,"_native_aeo_pack_noindex":"","_native_aeo_pack_excluded":"","_native_aeo_pack_nofollow":"","_native_aeo_pack_excluded_nofollow":"","_native_aeo_pack_sitemap_excluded":"","_native_aeo_pack_noimageindex":"","_native_aeo_pack_nosnippet":"","_native_aeo_pack_excluded_noimageindex":"","_native_aeo_pack_excluded_nosnippet":"","_native_aeo_pack_llms_exclude":"","_native_aeo_pack_schema_type":"","_native_aeo_pack_schema_entity":"","footnotes":""},"categories":[343],"tags":[365,366,367],"class_list":["post-60604","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-seo","tag-bucle-de-entradas","tag-generateblocks","tag-loop"],"openstation_lock":null,"openstation_contributors":[],"openstation_attached_media":[60615,40165,40168,40167,40166,40171,40169,40170,40173,40172,40174],"permalink_manager":null,"_links":{"self":[{"href":"https:\/\/jesusyesares.com\/en\/wp-json\/wp\/v2\/posts\/60604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jesusyesares.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jesusyesares.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jesusyesares.com\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jesusyesares.com\/en\/wp-json\/wp\/v2\/comments?post=60604"}],"version-history":[{"count":1,"href":"https:\/\/jesusyesares.com\/en\/wp-json\/wp\/v2\/posts\/60604\/revisions"}],"predecessor-version":[{"id":60623,"href":"https:\/\/jesusyesares.com\/en\/wp-json\/wp\/v2\/posts\/60604\/revisions\/60623"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jesusyesares.com\/en\/wp-json\/wp\/v2\/media\/60615"}],"wp:attachment":[{"href":"https:\/\/jesusyesares.com\/en\/wp-json\/wp\/v2\/media?parent=60604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jesusyesares.com\/en\/wp-json\/wp\/v2\/categories?post=60604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jesusyesares.com\/en\/wp-json\/wp\/v2\/tags?post=60604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}