I try to do something like this but is not working.
function aet_exclude_from_search( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', array( 'page', 'post', 'blog', 'tribe_events' ) );
$query->set('meta_query', array(
array(
'key' => 'EventHideFromUpcoming',
'value' => '0'
)
) );
}
return $query;
}
add_action( 'pre_get_posts','aet_exclude_from_search' );
Plugin Support
Jaime
(@jaimemarchwinski)
Hi @nunosarmento
Thanks for reaching out!
Are you looking to remove your events from the main WP search or are you looking to include them in the search and remove them from the event listings on your site?
Once I have some clarification here, I’d be happy to assist!
Thanks,
Jaime
Hi @jaimemarchwinski
I am looking to remove all “Hide from event listings” events from the main WordPress search.
Thank you.
Plugin Support
Jaime
(@jaimemarchwinski)
Hi @nunosarmento
Thanks for the clarification.
Unfortunately, customizations are beyond the scope of support that we provide, as per our support policy.
With that being said, we’d be happy to point you in the right direction.
You can try modifying the snippet provided in the following forum thread:
https://wordpress.org/support/topic/hide-past-events-in-the-main-wordpress-search/
I hope that helps!
Thanks,
Jaime
Hi @jaimemarchwinski
Thank you for your fast response.
This is not an extra customisations, it is a bug.
I assume if the “Hide from event listings” metabox option is ticked it will remove the events from any search query otherwise whats the point to have a “Hide events” if the events can be found in the WordPress search results.
Thank you for the above links but the requests are completely different they are not related.
Nuno
Plugin Support
Jaime
(@jaimemarchwinski)
Hi @nunosarmento
Thanks for your response! The “Hide from event listings” setting will only remove the events from the main calendar views like Month View and List View. It will still be searchable by default in the WordPress search and will still be accessible as a single event URL.
If you’d like to customize this, you could try excluding eventsbased on the custom meta. This has some examples: https://wordpress.stackexchange.com/questions/334194/exclude-posts-with-specific-metadata-from-search
You would have to target the search query at pre get posts, that link does not show how to do that.
I hope that helps!
Thanks,
Jaime
Plugin Support
Jaime
(@jaimemarchwinski)
Hey there! This thread has been inactive for a while so we’re going to go ahead and mark it Resolved. Please feel free to open a new thread if any other questions come up and we’d be happy to help. 🙂