Home › Forums › Calendar Products › Events Calendar PRO › Exclude Venues and Organizers from WordPress Search
- This topic has 10 replies, 3 voices, and was last updated 7 years, 7 months ago by Kevin.
-
AuthorPosts
-
August 20, 2016 at 9:46 am #1154055KevinParticipant
Is there any way (with a built in setting or additional code) to exclude venus and organizers from the wordpress search.
Given that these two CPTs aren’t related directly to my organization I’d like them not to show up in the wordpress search
August 22, 2016 at 9:12 am #1154381GeoffMemberHi Kevin,
Happy Monday and hope you had a great weekend!
You should be able to exclude specific post types from search using a function much like the one outlined in this post.
The two post types you want to do this for are:
- tribe_organizer
- tribe_venue
Cheers!
GeoffAugust 22, 2016 at 1:57 pm #1154542KevinParticipantYa, I caught that post and have tried it, even for just one of those CPTs but no luck.
Tried with a clean install of wordpress, base theme and the plugin but no luck.
Hmmm.
August 22, 2016 at 3:35 pm #1154587GeoffMemberHey Kevin!
I just stumbled across the Simply Exclude plugin which might be a good alternative. It will allow you to specify specific post types to exclude from the search action.
Will that work, by chance?
Cheers!
GeoffAugust 24, 2016 at 4:12 am #1155269KevinParticipantIdeally I’d like to not use an additional plugin to avoid all of the potential issues and bloat that comes along with it.
With that said, this isn’t working either, but it doesn’t work for my other CPTs either.
I’ll have to do some additional digging, but at the moment the only way for me to effectively exclude CPTs from searches is to include
'exclude_from_search' => true,
initially when the CPT is declared and not through other means. This works for other CPTs I have control over.August 24, 2016 at 7:26 am #1155310GeoffMemberinitially when the CPT is declared and not through other means. This works for other CPTs I have control over.
Yeah, that’s what I was hoping to accomplish with the filter from my first reply. I gave that a shot on my test site and it seems to do the trick.
Another way to go about it would be to write a filter for search itself, like this:
function exclude_from_search($query) { if ($query->is_search) { $query->set('post_type', 'post'); } return $query; } add_filter('pre_get_posts','exclude_from_search');
That will return only default WordPress posts in search.
Does that work for you as well?
Thanks!
GeoffAugust 24, 2016 at 2:43 pm #1155558KevinParticipantAlright, so here where I’m at.
Your last response, to modify the search query, works but it’s not ideal. Rather than limiting what’s search I have to state what’s included. Could become a pain depending on the number of post types to keep included in the search. It’s an option though. So Thank You!
But…
Back to your initial suggestion, this function:
add_action( 'init', 'update_my_custom_type', 99 ); function update_my_custom_type() { global $wp_post_types; if ( post_type_exists( 'my-custom-type' ) ) { // exclude from search results $wp_post_types['my-custom-type']->exclude_from_search = true; } }
I have it functioning for my CPTs. I think it was a cache problem initially of why it wasn’t working.
With that said, it’s still not working for
tribe_venue
* and I think I found the issue:on line
1396
of this file/wp-content/plugins/events-calendar-pro/src/Tribe/Main.php
the following exists:$venue_args['exclude_from_search'] = false;
It appears as if that line is taking precedent over the original function suggested. If I modify that line to include
true
as the option it will exclude the search results, obviously.Is there a way to include a modified Main.php file in my template folder (like I would have with files to override the standard calendar layout) so that upon plugin update I can keep any modifications I need to make to line 1396 in that file? If so, what might the folder structure look like?
* note: it appears that this was never an issue for tribe_organizer, I was simply including that in the original post because I assumed it worked the same way.
August 25, 2016 at 7:56 am #1155798GeoffMemberHey Kevin,
I brought in another pair of eyes to look at this and this function should do the trick:
/** * If The Events Calendar is active, restores the default exclude_from_search * property of the venue post type. */ function disable_public_venue_search() { if ( ! class_exists( 'Tribe__Events__Main' ) ) return; $tec = Tribe__Events__Main::instance(); $venue_args = $tec->getVenuePostTypeArgs(); $venue_args['exclude_from_search'] = true; register_post_type( Tribe__Events__Main::VENUE_POST_TYPE, apply_filters( 'tribe_events_register_venue_type_args', $venue_args ) ); } // ECP enables search for venues during wp_loaded:10 so we need this to run just after that add_action( 'wp_loaded', 'disable_public_venue_search', 50 );
You’re right that organizers are excluded by default. This will make sure the same is true of venues.
Let me know if this helps do the trick!
Geoff
August 28, 2016 at 10:12 am #1156876KevinParticipantThanks for taking the time to put this together. All seems to be working now. I appreciate your help with this.
August 29, 2016 at 7:46 am #1157055GeoffMemberMy pleasure! I’m so glad to hear all is working well and I appreciate you following up to let me know. 🙂
I’ll go ahead and close this thread but please feel free to let us know if any other questions come up and we’d be happy to help.
Cheers!
Geoff -
AuthorPosts
- The topic ‘Exclude Venues and Organizers from WordPress Search’ is closed to new replies.