• Resolved gottfrieds

    (@gottfrieds)


    The number of pages is calculated incorrectly in the query loop if an offset is specified. It seems that the offset is not deducted from the number of elements.

    • This topic was modified 2 years, 6 months ago by gottfrieds.

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support ying

    (@yingscarlett)

    Hi there,

    Your link leads to a 404 page, can you check?

    Thread Starter gottfrieds

    (@gottfrieds)

    The Page is … weiterer… and the blog starts with offset 5.

    Thanks

    Plugin Support David

    (@diggeddy)

    Hi there,

    hmmm…. we copied out what WP did with the core Query Loop block to resolve the offset issue. But it looks like that fix didn’t work either.

    Try adding this PHP snippet to your site:

    add_filter('found_posts', 'myprefix_adjust_offset_pagination', 1, 2 );
    function myprefix_adjust_offset_pagination($found_posts, $query) {
    
        //Define our offset again...
        $offset = 5;
    
        //Ensure we're modifying the right query object...
        if ( ! is_admin() && $query->is_main_query() ) {
            //Reduce WordPress's found_posts count by the offset... 
            return $found_posts - $offset;
        }
        return $found_posts;
    }

    and adjust the $offset = 5; to the required value.

    Thread Starter gottfrieds

    (@gottfrieds)

    I had a chance to check out the snippet. But as far as I was able to control it did not work.

    Plugin Support David

    (@diggeddy)

    Ok, so the static page will pose an issue.
    For testing try this:

    add_filter('found_posts', 'myprefix_adjust_offset_pagination', 1, 2 );
    function myprefix_adjust_offset_pagination($found_posts, $query) {
    
        //Define our offset again...
        $offset = 5;
    
        //Ensure we're modifying the right query object...
        if ( ! is_admin() ) {
            //Reduce WordPress's found_posts count by the offset... 
            return $found_posts - $offset;
        }
        return $found_posts;
    }

    Let me know if that works

    Hi there! We haven’t heard back from you for a while now so we’re going to go ahead and set this topic as resolved. Feel free to open a new topic if you need assistance with anything else GB free related.

    Thread Starter gottfrieds

    (@gottfrieds)

    Sorry for answering so late – forgot it. This proposal worked very well.

    Plugin Support David

    (@diggeddy)

    Glad to hear this worked.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Incorrect pagination in query block’ is closed to new replies.