How to dynamically change 'Posts per page' from 4 to 12 depending on Pagination

Howdy, all

Building my first client site in Bricks and I’m wondering if anyone could shed some light on this issue I’m having with the Query Loop and Posts Per Page.

  • I have a ‘main’ news page with two query loops consisting of two featured posts (Only showing on main page, set by a condition), and 4 smaller posts. All good so far ✅
  • When I navigate to page 2,3 etc (as expected) I only get 4 posts per page ❌
  • I see that the ‘Posts per page’ option for the Query loop is not dynamic, so it will always be set to 4. How do I make each paginated page display 12 posts instead of 4?

Additional information: The condition to get the paged query var is a function I added in functions.php:

add_filter( 'bricks/code/echo_function_names', function() {

return [

'is_dynamic_button_label', // Name of your function

'get_query_var'

];

} );

Try Filter: bricks/posts/query_vars – Bricks Academy

You need something like:

add_filter( 'bricks/posts/query_vars', function( $query_vars, $settings, $element_id, $element_name ) {
    if ( $element_id == '*your-brick-element-id*' && is_paged() ) {
        $query_vars['posts_per_page'] = 12;
    }

    return $query_vars;
}, 10, 4 );