"Query," "Query Loop," "Filter" Explained

This is coming from a beginner, and I’ve tried watching videos and searching the discourse, but would someone be able to explain the basic difference between and structure of “query,” “query loop,” and “filter”?

For example a question I have is:
Why does just the ‘Query’ block not show any of the queries? So far I have only gotten objects to show with ‘Query loop.’

And when I try to follow this video I can’t get it working because the lay-out and names of the blocks have in the meantime changed completely.

I’m asking because I’m trying to build a calendar and I’m already halfway using Custom Type Post UI Plugin and Advanced Custom Fields. I only need to input the dynamic data of 10 events and show a see more page or something.

You are almost there,
here is the logic
first you add a section
within add a query block
set your query with your custom post type
inside the Query block
you need to add a Query template block and in it you will add paragraphs, headings, images all with dynamic datas linked to your custom fields.
You should then see a basic layout of your custom query and then you can start styling it.

The filtering is a whole different animal in itself, that will start from there if you need so…

Hope you can get the logic and get started…

3 Likes

Doing queries is a twofold process. Mainly because of how Wordpress works fundamentally.

I’ll preface this by saying that often when you see things that might seem unintuitive, it is often because it’s how Wordpress works, and Cwicly is just passing it through and trying to simplify without obscuring too much.

The Query block is sending instructions to the database telling it exactly what information to fetch.
So this is where you would tell it you want to query a particular post type, along with any other parameter that goes into how WP creates/stores posts. This means you can query for authors, dates, taxonomies, metadata, and so much more.

This block does the heavy lifting. It goes in and retrieves all this information and has it at the ready. The problem now is that this is a LOT of information, and you probably only need to show some of it to users on the front-end.

This is where the Query Template (you call this the Query Loop, but technically, both together would be a Query Loop) comes in. The query template is what users will see and interact with. Once you have created and set up the Query, the dynamic elements you create here will pull data from the posts contained within.

This block functions more like what you would be familiar with in terms of layout. It is a container element (think div, or section) inside which you can do whatever layout you decide to create. The default is a grid layout, but it doesn’t have to be. It’s easier, though, since you will be returning multiple items based on the query above.

For your purposes, as you’ve described, you should add fields for the event name (dynamic data = Post title); event date (ACF field), location (if necessary… also ACF), image (could be featured image), etc.

Once you add these, as @JuGa said above, you should start to see information popping in. And from there you can start moving things around as you see fit.

Filtering really requires a separate think, but makes sense once you get it. I would make sure you get the Query process locked in and understood, then move on to that.

If you do need more help, I would be glad to help you set up a basic filter based on what you’re trying to accomplish.

8 Likes

amazing reply! this is exactly the kind of explanation i was looking for and i understand the logic now. thanks

2 Likes

thanks! much better answer in depth, I wrote mine on the go, in the train from my phone… ahahaha thank you!

1 Like