I'm working a Wordpress site that was built by another developer using the Flatsome theme.
I'm trying to modify the search query to include the post types: 'attachment' and 'page' using the following query:
function cia_search_filter($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query->is_search) {
$query->set('post_type', array( 'post', 'attachment', 'page' ) );
}
}
}
add_action('pre_get_posts','cia_search_filter');
If I var_dump $query->is_main_query()
and $query->is_search
both return false.
Is this specific to this theme and is there a reason why this doesn't work?