In a plugin, I have this simple code:

add_filter( 'the_posts', 'process_search_results', 10, 2 );
function process_search_results($posts, $query=false) {
    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.

  • 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 Feb 22 '17 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.