• I’ve got a problem with the found_posts aspect of Relevanssi. I’m creating my own WP_Query object and calling it like so:

    $q = new WP_Query($query_args);
    $posts = $q->get_posts();
    $count = $q->found_posts;

    So this is not the global $wp_query, it’s a separate instance. This code isn’t working when Relevanssi is switched on – found_posts is always zero. I think it comes down to the relevanssi_query method in relevanssi/lib/search.php:

    function relevanssi_query($posts, $query = false) {
        ...
        global $wp_query;
        ...
        $posts = relevanssi_do_query($wp_query);
        ...
    }

    It seems to be completely ignoring the $query argument, and always uses the global. Even if the arguments in the global query are the same, this means it doesn’t store the found_posts value where it’s needed.

    Am I misunderstanding, or is this a bug?

    http://ww.wp.xz.cn/plugins/relevanssi/

Viewing 1 replies (of 1 total)
  • Plugin Author Mikko Saari

    (@msaari)

    First of all, why are you creating a new WP_Query object? If you only want to find out the number of posts found by the search, just take a look at $wp_query->found_posts. It’s right there.

    Second, this all has to do with the fact that there’s no official way to integrate a search plugin to WordPress. There’s no filter that says “here’s a search query, now get us posts”. It’s a bit of a hack, and you’re seeing the results. Relevanssi has trouble, if there are several query_posts() or new WP_Query() calls on the search results page.

    So, not a bug, but an unfortunate feature.

Viewing 1 replies (of 1 total)

The topic ‘Confusion with $wp_query->found_posts’ is closed to new replies.