I'm trying to add a custom post type into the seach facility so that it searches those posts as well as the pages on a site.
I have seen the pre_get_posts function and have it set up like the below in my themes functions.php file but its not firing at all. I have put get_current_screen() function in there to test but it doesn't return anything.
function searchAll($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query->is_search) {
$query->set('post_type', array( 'post', 'movie' ) );
}
}
}
add_action('pre_get_posts','searchAll');
I also tried to just have the $query->set('post_type', array( 'post', 'movie' ) ); line not in any of the if statements but nothing is happening. What am I doing wrong?
Please help!
add_action( 'pre_get_posts', 'searchAll', 1 );
$query->is_search
should be$query->is_search()
add_action( 'pre_get_posts', 'searchAll', 999 );
$query->is_search()