Title: Taking advantage of query loops
Published: 29 April 2024
Last modified: 13 September 2024

---

[Home](https://learn.wordpress.org)[Courses](https://learn.wordpress.org/courses/)
[Intermediate WordPress User](https://learn.wordpress.org/course/intermediate-wordpress-user/)
Taking advantage of query loops

 [ Exit Course ](https://learn.wordpress.org/course/intermediate-wordpress-user/)

 1.   a.  [   User management  ](https://learn.wordpress.org/lesson/user-management/) 
         [Preview](https://learn.wordpress.org/lesson/user-management/)
 2.   1 lesson
 3.   a.  [   Migrating your site Part 1: Changing to a new host and domain  ](https://learn.wordpress.org/lesson/migrating-your-site-part-1-changing-to-a-new-host-and-domain/)
         [Preview](https://learn.wordpress.org/lesson/migrating-your-site-part-1-changing-to-a-new-host-and-domain/)
      b.  [   Migrating your site Part 2: Changing your host but keeping your domain  ](https://learn.wordpress.org/lesson/migrating-your-site-part-2-changing-your-host-but-keeping-your-domain/)
         [Preview](https://learn.wordpress.org/lesson/migrating-your-site-part-2-changing-your-host-but-keeping-your-domain/)
 4.   2 lessons, 2 quizzes
 5.   a.  [   Differentiating between homepage display settings and various templates  ](https://learn.wordpress.org/lesson/differentiating-between-homepage-display-settings-and-various-templates/)
         [Preview](https://learn.wordpress.org/lesson/differentiating-between-homepage-display-settings-and-various-templates/)
      b.  [   Personalizing your 404 template  ](https://learn.wordpress.org/lesson/personalizing-your-404-template/)
         [Preview](https://learn.wordpress.org/lesson/personalizing-your-404-template/)
      c.  [   Customizing the search results template  ](https://learn.wordpress.org/lesson/customizing-the-search-results-template/)
         [Preview](https://learn.wordpress.org/lesson/customizing-the-search-results-template/)
      d.  [   Customizing your single posts template  ](https://learn.wordpress.org/lesson/customizing-your-single-posts-template/)
         [Preview](https://learn.wordpress.org/lesson/customizing-your-single-posts-template/)
      e.  [   Creating a custom template  ](https://learn.wordpress.org/lesson/creating-a-custom-template/)
         [Preview](https://learn.wordpress.org/lesson/creating-a-custom-template/)
      f.  [   Adding and customizing a category template  ](https://learn.wordpress.org/lesson/adding-and-customizing-category-template/)
         [Preview](https://learn.wordpress.org/lesson/adding-and-customizing-category-template/)
      g.  [   Styling your site with Global Styles  ](https://learn.wordpress.org/lesson/styling-your-site-with-global-styles/)
         [Preview](https://learn.wordpress.org/lesson/styling-your-site-with-global-styles/)
      h.  [   Using the Style Book  ](https://learn.wordpress.org/lesson/using-the-style-book/)
         [Preview](https://learn.wordpress.org/lesson/using-the-style-book/)
 6.   8 lessons, 4 quizzes
 7.   a.   [   Taking advantage of query loops  ](https://learn.wordpress.org/lesson/taking-advantage-of-query-loops-2/)
          [Preview](https://learn.wordpress.org/lesson/taking-advantage-of-query-loops-2/)
      b.   [   Using the Comments block  ](https://learn.wordpress.org/lesson/using-the-comments-block/)
          [Preview](https://learn.wordpress.org/lesson/using-the-comments-block/)
      c.   [   Designing with the Columns block  ](https://learn.wordpress.org/lesson/designing-with-the-columns-block/)
          [Preview](https://learn.wordpress.org/lesson/designing-with-the-columns-block/)
      d.   [   Using the Group block  ](https://learn.wordpress.org/lesson/using-the-group-block/)
          [Preview](https://learn.wordpress.org/lesson/using-the-group-block/)
      e.   [   Designing with Row and Stack blocks  ](https://learn.wordpress.org/lesson/designing-with-row-and-stack-blocks/)
          [Preview](https://learn.wordpress.org/lesson/designing-with-row-and-stack-blocks/)
      f.   [   Uncovering the Cover block  ](https://learn.wordpress.org/lesson/uncovering-the-cover-block/)
          [Preview](https://learn.wordpress.org/lesson/uncovering-the-cover-block/)
      g.   [   Advanced WordPress block layouts  ](https://learn.wordpress.org/lesson/advanced-wordpress-block-layouts/)
          [Preview](https://learn.wordpress.org/lesson/advanced-wordpress-block-layouts/)
      h.   [   Building a page with only patterns  ](https://learn.wordpress.org/lesson/building-a-page-with-only-patterns/)
          [Preview](https://learn.wordpress.org/lesson/building-a-page-with-only-patterns/)
      i.   [   Creating your own custom synced and non-synced patterns  ](https://learn.wordpress.org/lesson/creating-your-own-custom-synced-and-non-synced-patterns/)
          [Preview](https://learn.wordpress.org/lesson/creating-your-own-custom-synced-and-non-synced-patterns/)
      j.   [   Organizing your Media Library  ](https://learn.wordpress.org/lesson/organizing-your-media-library/)
          [Preview](https://learn.wordpress.org/lesson/organizing-your-media-library/)
 8.   10 lessons, 4 quizzes
 9.   a.  [   SEO strategies  ](https://learn.wordpress.org/lesson/seo-strategies/) [Preview](https://learn.wordpress.org/lesson/seo-strategies/)
      b.  [   What is accessibility, and why is it important?  ](https://learn.wordpress.org/lesson/what-is-accessiblity-and-why-is-it-important/)
         [Preview](https://learn.wordpress.org/lesson/what-is-accessiblity-and-why-is-it-important/)
      c.  [   Testing your content for accessibility  ](https://learn.wordpress.org/lesson/testing-your-content-for-accessibility/)
         [Preview](https://learn.wordpress.org/lesson/testing-your-content-for-accessibility/)
 10.  3 lessons, 2 quizzes
 11.  a.  [   Tools: Export and Import  ](https://learn.wordpress.org/lesson/tools-export-and-import/)
         [Preview](https://learn.wordpress.org/lesson/tools-export-and-import/)
      b.  [   Tools: Site Health  ](https://learn.wordpress.org/lesson/tools-site-health/)
         [Preview](https://learn.wordpress.org/lesson/tools-site-health/)
 12.  2 lessons, 1 quiz
 13.  a.  [   Managing Settings: General  ](https://learn.wordpress.org/lesson/managing-settings-general-2/)
         [Preview](https://learn.wordpress.org/lesson/managing-settings-general-2/)
      b.  [   Managing Settings: Writing  ](https://learn.wordpress.org/lesson/managing-settings-writing-2/)
         [Preview](https://learn.wordpress.org/lesson/managing-settings-writing-2/)
      c.  [   Managing Settings: Reading  ](https://learn.wordpress.org/lesson/managing-settings-reading-2/)
         [Preview](https://learn.wordpress.org/lesson/managing-settings-reading-2/)
      d.  [   Managing Settings: Discussion  ](https://learn.wordpress.org/lesson/managin-settings-discussion/)
         [Preview](https://learn.wordpress.org/lesson/managin-settings-discussion/)
      e.  [   Managing Settings: Media  ](https://learn.wordpress.org/lesson/managing-settings-media/)
         [Preview](https://learn.wordpress.org/lesson/managing-settings-media/)
      f.  [   Managing Settings: Permalinks  ](https://learn.wordpress.org/lesson/managing-settings-permalinks/)
         [Preview](https://learn.wordpress.org/lesson/managing-settings-permalinks/)
      g.  [   Managing Settings: Privacy Policy  ](https://learn.wordpress.org/lesson/managing-settings-privacy-policy/)
         [Preview](https://learn.wordpress.org/lesson/managing-settings-privacy-policy/)
 14.  7 lessons, 2 quizzes
 15.  a.  [   Website optimization  ](https://learn.wordpress.org/lesson/website-optimization/)
         [Preview](https://learn.wordpress.org/lesson/website-optimization/)
      b.  [   Image optimization  ](https://learn.wordpress.org/lesson/image-optimization/)
         [Preview](https://learn.wordpress.org/lesson/image-optimization/)
 16.  2 lessons, 2 quizzes
 17.  a.  [   Domain management: Understanding DNS records  ](https://learn.wordpress.org/lesson/domain-management-understanding-dns-records/)
         [Preview](https://learn.wordpress.org/lesson/domain-management-understanding-dns-records/)
 18.  1 lesson, 1 quiz
 19.  a.  [   Essential security plugin features and settings  ](https://learn.wordpress.org/lesson/essential-security-plugin-features-and-settings/)
         [Preview](https://learn.wordpress.org/lesson/essential-security-plugin-features-and-settings/)
 20.  1 lesson

### Content Creation

# Taking advantage of query loops

## Transcript

### ⏎ Introduction

In this lesson we will learn more about query loops and using the Query Loop block.
Let’s first talk about the Query Loop block. This powerful block can be used to 
display posts based on specified parameters. This is also the block used on your
blog page to display all your posts and will allow you to ask the database to show
you all the posts about a specific topic. For example, you can ask to see all the
posts written about gluten-free recipes. Or you might want to see posts about reviews
of computer games.

### Structure of a Query Loop block

Each Query Loop block comprises various blocks like the Post Featured block, the
Categories block, the Post Title block, the Post Author block, the Post Excerpt 
block, etc. While you won’t be able to edit the content of these nested blocks, 
you can customize the appearance and layout, including adding or removing additional
blocks as you’d like.

### Examples

Let’s look at a few example websites to see how they have used query loops. In our
first example, a query loop has been used to highlight the latest stories, recognizing
women’s creativity, leadership, courage, and innovation. Below that, a query loop
has been used to display blog posts. In the second example, query loops have been
used to display different types of recipes. First, we have breakfast recipes and
amazing appetizers if we scroll down. In our last example, a query loop has been
used to create a news page. Let’s first look at how to modify a Query Loop block
and use patterns.

### Editing

So let’s make our way to Appearance and click on Editor. This will take us to our
Site Editor, and currently, we are on our blog home template, which displays all
our blog posts. Let’s open the list to see how our Query Loop block is structured.
At the top, we will see the Featured Image block. Then we have the Post Title block
followed by the Post Meta blocks. They include the Post Date block, the Post Author
block, and the Categories block. Lastly, there is the Post Excerpt block. But of
course, we can alter what we want to have displayed. So, for example, let’s delete
the Post Excerpt block. Select the Post Title block and drag and drop it above the
Featured Image block. The great thing about updating the Query Loop block is that
if you change something in one post, it will appear everywhere else.

### Start blank versus patterns

But what if we want to use a completely different pattern and layout? Well, we can
click on Replace in our block toolbar and browse through the various patterns that
come with your theme. And when you select a pattern, you can, of course, customize
it as you please. You will have two options when you add a new Query Loop block.
You can choose a pattern, or you can start blank. When you click Start blank, you
can select one of the variations. In this case, I will select Title, Date, and Excerpt.
Then we can modify it further. Let’s go ahead and add a Featured Image block below
the title. Thereafter, we can open up Styles and change the aspect ratio to, for
example, 4×3 to ensure that all the post-featured images display the same.

### Filters

Next up, we will look at taxonomies or filters and how to use the sidebar settings.
I’ve created a lifestyle page and only want to see posts related to this topic. 
So, I will select the Query Loop block and open my sidebar settings. The first thing
we have to do is deselect the Inherit query from the template, as I want to customize
the settings of the query loop. When you scroll down, you can filter your posts 
using taxonomies, such as categories and tags, authors, and even keywords. I will
select taxonomies as I’ve created a lifestyle category and only want to see posts
with this category displayed. All posts that don’t fall under this category will
be excluded when I add the lifestyle category.

You also have the option to display posts from a specific author. Once I select 
the Query Loop block again, I will go to my sidebar settings, click on Filters, 
select Authors, and select the person whose posts I want to display. Now, we will
only see posts written by Roger Lister. You can, of course, also choose a keyword
and only display posts that contain that word or words in the text.

### Sidebar settings

Lastly, let’s have a closer look at our sidebar settings. As mentioned, I’ve deselected‘
Inherit query from the template’ to customize the query. If you toggle it on, certain
customization options will be hidden. If you toggle it off, more customization options
will appear. When you add a new Query Loop block to a post or template, it is also
important to turn this off, as your Query Loop block might not appear on the front
end. The next option is post type. At the moment we are displaying blog posts. But
you can also display pages or even custom post types. Below that, you have the option
to order your posts from newest to oldest, oldest to newest, or alphabetically. 
Next, let’s talk about sticky posts. A sticky post is a post that sticks to the 
top of your blog page, and the option in your sidebar settings will allow you to
include sticky posts, exclude them, or only show sticky posts. Below sticky posts,
we will see the option to turn off ‘Force page reload.’ This will allow someone 
to browse through posts without a page reloading and could contribute to a better
user experience. Finally, we have already discussed using filters.

### Conclusion

All the best as you take advantage of this powerful block to display posts.

## Practical

Use WordPress Playground to test your knowledge.

 1. Create two posts, add some dummy content, and post featured images. If you don’t
    have any images on your computer, you can use https://unsplash.com/. One photo 
    should relate to [Fitness](https://unsplash.com/s/photos/fitness?license=free) (
    opens in a new tab), and the other to [Nutrition](https://unsplash.com/s/photos/nutrition?license=free)(
    opens in a new tab).
 2. Create two categories, namely Fitness and Nutrition. Add the Fitness category to
    one of the posts and the Nutrition category to the other.
 3. Create a new page, add the Query Loop block, and select a pattern. Name the page
    Nutrition.
 4. De-select ‘Inherit query from the template.’
 5. Navigate to Filters > Taxonomies > Categories and select Nutrition to display only
    posts tagged with Nutrition.

 This is a preview lesson

Register or sign in to take this lesson.

 [ Take course ](https://learn.wordpress.org/course/intermediate-wordpress-user/)

 [ Sign in ](https://login.wordpress.org/?redirect_to=https%3A%2F%2Flearn.wordpress.org%2Flesson%2Ftaking-advantage-of-query-loops-2%2F&locale=en_US)

##  Suggestions

 Found a typo, grammar error or outdated screenshot? [Contact us](https://learn.wordpress.org/report-content-feedback/).