-
alyssag022
Hi there!
I have a query loop on my homepage which you can see here:
https://erria.xyz/?share=6cbe7d85b1c878a1670692bf8a8d2d3ac13be6232e52a332c2bb48e5708f32fa
Currently, the loop is 127 pages and displays ALL of my posts. However, I would like to limit the loop to only show 40 random posts, or 5 pages, at a time?
Can you let me know how I can do that?
Thank you!
-
Fernando
Hi Alyssag,
Can you try adding
limit-pages
to the class list of the Grid inside the GB Query Loop.Adding Custom Classes: https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/
Then, add this snippet:
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) { if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'limit-pages' ) !== false ) { $query_args['max_num_pages'] = '5'; } return $query_args; }, 10, 2 );
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
-
alyssag022
Hi,
Thanks so much for your quickly reply but unfortunately it did not work :/
-
David
Hi there,
that code won’t work as the
max_num_pages
is not a wp_query argument, it’s a query property that stores the total number of pages.What we need to do is filter the
paginate_links
args for that post navigation and that unfortunately is not possible at this time.
- You must be logged in to reply to this topic.