I want to inject additional search results along with the search results provided by WordPress for the site search feature. Basically, I need to find the WP_Query object that the search uses, and modify it.

I figure I should use the posts_pre_query filter, and return an array of post objects - some of which will be real post objects, and others which will be "fake" posts objects that represents results from the other sources.

The problem I have is, how do I detect that this is a public search query - what characterizes a WP_Query instance that is a public search result?

1 Answer 1

add_filter( 'pre_get_posts', '__filter_pre_get_posts' );
function __filter_pre_get_posts( $query ) {

    // this is to detect a public search query 
    if ( ! is_admin() && $query->is_search ) {

        // DO your magic here...


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.