Archived topic
Custom Page with Query loop
33 replies · Started by Dev on August 5, 2022
What other snippet ?
Hello,
Below is the other snippet that Fernando gave me.
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 );
What shall I do can you please tell me clearly, David.
Are these separate query loops you want to make ? ie.
1. A Loop with the code that Fernando provided.
2. A loop that has Posts and Pages
Hello,
Below is the reply to your questions.
1. A Loop with the code that Fernando provided.
Reply: I didn't get what you meant.
2. A loop that has Posts and Pages
Reply: Yes, I want to make a loop (a page) where I want to display posts and pages both with the post/page ids.
Are you getting me? Do you understand my need? Or shall I explain further?
So where are you using Fernandos code ? this:
https://generatepress.com/forums/topic/custom-page-with-query-loop/#post-2303980
Hello,
I'm using the Fernando code in the Snippet plugin.
Please check the below screenshot
Can you please tell me what I shall do further?
Try replacing the one I gave here: https://generatepress.com/forums/topic/custom-page-with-query-loop/#:~:text=1%3A16%20am-,%232303980,-EDIT%20%7C%20MOVE
With this:
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-query' ) !== false ) {
$query_args[ 'post_type' ] = array('post', 'page');
$query_args['post__in'] = array(395672, 394831, 392713);
$query_args['orderby'] = 'post__in';
}
return $query_args;
}, 10, 2 );
That's the two snippets combined.
Hello,
I used the new code. But still, the problem is the same. The page is showing blank. Nothing is coming there.
Can you please tell me what I should do?
Can you try clearing cache?
Hello,
I did that. I cleared the cache.
Is it seeable at your end in the browser?
Can you give a link to a specific post/page you’re trying to add to the Query?
Hello,
I have added the URL of page in the private box you can check.
Can you try removing the category parameter in your Query Loop?
Okay, and after that, what should I select in the Post type option?
You can leave it as is.