1

In a plugin, I have this simple code:

add_filter( 'the_posts', 'process_search_results', 10, 2 );
function process_search_results($posts, $query=false) {
    print_r($posts);
    return $posts;
}

This shows the list of posts that will be looped over in the loop. But on a search page, an empty array (Array()) is printed, while the search results are still shown. Why is $posts empty for searches?

Some background: I'll try to code a custom search plugin that should merge results from an external data source into the default results.

1
  • I have the plugin Relevanssi installed, that also hooks into the_posts. So changing the filter priority from 10 to 20 gives me the post list even on search pages. How embarrassing ...
    – z80crew
    Commented Feb 22, 2017 at 15:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.