Archived topic
Exclude redirected pages from page search results
7 replies · Started by Olga on June 11, 2019
Hello,
Is there a way to exclude redirected pages from the page search results (when the user uses the search icon on the website)
Best,
Olga
Hi there,
are you using a plugin for your redirections?
Yes, Redirection.
May need to speak with the plugin author, but i would assume its using a custom post type, so you could filter the search results for only posts and pages with this PHP snippet:
add_action('pre_get_posts','search_filter');
function search_filter( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
if ( $query->is_search) {
$query->set('post_type', array('post', 'page') );
}
}
}
Thank you, the snipped does not work though.
Would you be able to ask the Redirect plugin author?
If they can't help hiding it from the search results, they should be able to tell us what the name of the post template is.
ok, I sent a form, let's hope they answer. Thank you!
Keep us posted - if you don't hear back soon let us know