Include Custom Post Types in Search Results

The following code will make Custom Post Types on your WordPress site appear in search results:


function searchAll( $query ) {
    if ( $query->is_search ) { $query->set( 'post_type', array( 'site', 'plugin', 'theme', 'person' )); }
     return $query;
}

add_filter( 'the_search_query', 'searchAll' );

Change line 4 to the post types you want.

Discussion
[  0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!