Hi There @sylvianibley
Thanks for writing in! First of all, please note that custom development is outside our scope of the support and we only provide a guideline for specific customizations.
Since you have a child theme already setup, try adding the following code into your child theme’s functions.php file.
// Remove Portfolios from Search Results
add_action( 'pre_get_posts', 'themeco_exclude_portfolio_from_search' );
function themeco_exclude_portfolio_from_search( $query ) {
// First, make sure this isn't the admin
if( is_admin() || ! $query->is_main_query() )
return;
// If this is a search result query
if( $query->is_search() ) {
// Gather all searchable post types
$in_search_post_types = get_post_types( array( 'exclude_from_search' => false ) );
// The post type you're removing, in this example 'portfolio'
$post_type_to_remove = 'x-portfolio';
// Make sure you got the proper results, and that your post type is in the results
if( is_array( $in_search_post_types ) && in_array( $post_type_to_remove, $in_search_post_types ) ) {
// Remove the post type from the array
unset( $in_search_post_types[ $post_type_to_remove ] );
// set the query to the remaining searchable post types
$query->set( 'post_type', $in_search_post_types );
}
}
}
Thanks!