Pagination on loop query loop args

I’ve got two query loops on my site homepage: https://zeroacquire.com/

They both pull from the “Listings” post type, and using a filter and CSS classes, I’m excluding sold projects from the first loop and only showing sold projects in the second one using listing_status meta. Here’s the code for that:

add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
    if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'listing-loop' ) !== false ) {
        $query_args['meta_query'] = array(
            array(
                'key' => 'listing_status',
                'value' => 'approved',
                'compare' => '=',
                'posts_per_page' => 9,
            ),
        );
    }

    if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'sold-loop' ) !== false ) {
        $query_args['meta_query'] = array(
            array(
                'key' => 'listing_status',
                'value' => 'sold',
                'compare' => '=',
                'posts_per_page' => 6,
            ),
        );
    }

    return $query_args;
}, 10, 2 );

The problem is that pagination is still showing as 3 pages, even though there aren’t 3 pages of listing posts to show.

I think this is because the pagination is still including the 3 posts with listing_status of sold.

How can I modify that to make sure pagination is correct and doesn’t show a blank third page?

Hey @ian, you found a bug actually. Thank you for pointing that out. I’ll be fixing this on the next patch.

1 Like