Archived topic
Custom Page with Query loop
33 replies · Started by Dev on August 5, 2022
Hello,
I want to create a page where I want to use the query loop.
On that page, I want to display the post through post ids. So can you please tell me how I can do that? Any step-by-step article or video on it.
Hi Dev,
Here are a few steps:
1. In your admin page go to Pages > Add New.
2. Add a GenerateBlocks Query Loop Block.
3. Add a parameter - Include posts
4. Add the posts you wish to include.
Hi,
But there is no option for adding the posts via post ids
Add my-query to the class list of the Grid Block within the Query loop block, then add this PHP snippet:
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-query' ) !== false ) {
$query_args['post__in'] = array(395672, 394831, 392713);
$query_args['orderby'] = 'post__in';
}
return $query_args;
}, 10, 2 );
Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets
Replace 395672, 394831, 392713 with your post IDs, and add more if needed.
Hello,
First, I added the my-query to the class list of the Grid Block within the Query loop block. See the screenshot: https://prnt.sc/u1VJhUh-qd5k
Then next, I added the PHP snippet through Code snippet plugging. See the screenshot: https://prnt.sc/EHpbRzxKuUOq
I followed both the steps, but after that, nothing is coming on that page. It's blank. I'm adding the page URL in the private box.
Please let me know what shall I do.
Hi there,
It should work, I just tested it on my site.
Can you provide the admin login so we can take a look at the backend?
Please disable your cache plugin for us to inspect.
Let me know!
Hello,
I have added the wp-login details in the private box.
What's the username?
I have added the username in the private box.
You have this category selected in the query loop block, can you confirm that the post IDs in your PHP code belong to this specific category?
https://www.screencast.com/t/89TxQnJz
Hi,
The post ids in my PHP snippet are of the Page(s).
I think it is possible to display them?
If NOT, then what's the solution?
The ids are pages, not posts? But they belong to that category?
If so, you need to choose pages as post types.
Hi,
I want to display posts and pages both on that page.
Is it possible? If yes, then please tell me how.
Are you getting me?
It should be possible. You can follow David’s instructions here: https://community.generateblocks.com/t/multiple-post-types-in-query-loop/850
Hello,
I checked the David instruction on the link you gave me.
There is some PHP snippet over there.
So, I want to know what I shall do with it.
Shall I remove the older PHP snippet which you gave me, or what exactly should I do? Please help me out it's urgent.