WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Main query fires twice, pagination is broken (2 posts)

  1. Aroniel
    Member
    Posted 1 year ago #

    Hi,

    I'm working on a rather convoluted WordPress setup which uses quite a lot of plugins. (BuddyPress, bbPress and WPML to name a few)

    Unfortunately, the paging on the BuddyPress front page no longer seems to be working.
    When I add some basic echos in WP's query.php file, I get the following results (these numbers follow eachother, so it appears the query fires twice) :

    posts: 14 (found_posts)
    ppp: 10 (posts_per_page)
    max: 2 (max_num_pages)
    
    posts: 10
    ppp: 10
    max: 1

    When I check to see if I'm in the main query when echoing the numbers, I get the following results:

    posts: 14
    ppp: 10
    max: 2

    So apparently, the main query is returning the correct results, but the main query results aren't the ones being displayed/used on the homepage.

    I wrote my own plugin which hooks into pre_get_posts, but this isn't skewing the results. If I disable the hook, it's still showing the query being run twice, with slightly different results, since my custom plugin excludes a few categories from the results.

    Would anyone know how I can get the query to get the correct number of posts and fix the pagination? What may be causing the query to fire twice?

  2. Aroniel
    Member
    Posted 1 year ago #

    Fixed. Using the debug_print_backtrace function, I was able to determine which function was responsible for firing the second query and there I found the culprit was WPML. After setting the 'Blog posts to display' setting from 'All posts (display translation if it exists or posts in default language otherwise).' to 'Only translated posts', it worked perfectly.

Topic Closed

This topic has been closed to new replies.

About this Topic