Hi,
So, I was trying to figure out how to add pages into my search results on my site in addition to posts, and I came across this thread from 2019:
Specifically, I added this snippet into the functions.php in my child theme from this thread as the directions specified.
function wp_search_filter( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', array('post','page') );
}
return $query;
}
add_filter('pre_get_posts','wp_search_filter');
…and this worked! The search function on my site now included results from pages as well as posts.
Here’s the problem though. I then went onto my next task to edit something in a header, and I discovered that in the Pro backend, all of my headers and footers were now gone from the lists, and the search function for searching through your headers, content, and footers in the Pro backend didn’t work. So, while this solution worked fine for the search bar on the website, it royally screws up the Pro Backend search functions for headers, footers, and content.
Any ideas how the above script can be modified so that it still works the same for the actual search bar on the website and doesn’t mess up the search and header/footer/content listings when you’re working in the Pro backend?
Unfortunately, my employer forbids outside access to our servers, so I am unable to share a login, however I can provide screenshots if necessary. it should be pretty easily replicated though. Just paste that into your child theme’s functions.php and then go into Wordpress to your Pro backend and you’ll see your website’s headers and footers are suddenly missing from the lists and searching for them doesn’t work.
I am using the most recent versions of both Wordpress (5.7.1) and Pro (4.3.3)
Thanks!