Excluding certain categories from the search function
WordPress Event Management, Calendars & Registration › Forums › General Question › Excluding certain categories from the search function
This topic contains 13 replies, has 3 voices, and was last updated by Stephen Harris 4 months, 2 weeks ago.
-
AuthorPosts
-
October 16, 2018 at 11:11 am #31848
Hello
Is it possible to exclude certain categories from being returned in the search function?Also, is it possible to prevent certain categories from showing in the category dropdown for the search funtion.
I’ve tried listing them by slug, but those not listed are appearing in the drop-down.
[event_search event_start_after=”now” posts_per_page=”8″ event-category=”music,adult-outreach,education,exhibition,featured,family,other-events,special-services” filters=”date,event_category”]
Here is the page: http://minster.southwellminster.org/event-search/
Many thanks for your help, I’m finding it a very useful plugin.
Best wishes
MadeleineMadeleine ParkynOctober 25, 2018 at 10:41 am #31931Hi
I’d really appreciate some guidance with the query above about excluding certain categories from the displayed search results.Many thanks
MadeleineMadeleine ParkynOctober 29, 2018 at 9:00 pm #31960Hi Madeleine,
There isn’t an option to do this, so you would have to modify the code base directly. In line of 203 of includes/shortcodes.php, there is:
$tax = get_taxonomy( 'event-venue' ); $venue_objs = eo_get_venues(); if ( $venue_objs ) { ...
You can modify the
$venue_objs
objecto filter out any venues you don’t want:$tax = get_taxonomy( 'event-venue' ); $venue_objs = eo_get_venues(); $venue_objs = array_filter($venue_objs, function($venue) { $whitelist = array('music', 'adult-outreach', 'education'); return in_array($venue->slug, $whitelist); }); if ( $venue_objs ) { ...
Stephen HarrisOctober 30, 2018 at 8:59 am #31971Many thanks Stephen. I’ll give it a go.
With best wishes
MadeleineMadeleine ParkynOctober 30, 2018 at 12:56 pm #31972Hi Stephen
I’m a bit confused. I asked about catgories, but your reply refers to venues, with category slugs?
Many thanks
MadeleineMadeleine ParkynOctober 30, 2018 at 11:41 pm #31983Sorry, for categories line 321 has
$taxonomy = get_taxonomy( $filter ); $term_objs = get_terms( $taxonomy->name, array( 'hide_empty' => 0 ) );
You can modify that to:
$taxonomy = get_taxonomy( $filter ); $term_objs = get_terms( $taxonomy->name, array( 'hide_empty' => 0 ) ); if('event-category' === $filter){ $term_objs = array_filter($term_objs, function($term) { $whitelist = array('music', 'adult-outreach', 'education'); return in_array($term->slug, $whitelist); }); }
Stephen HarrisNovember 6, 2018 at 10:58 am #32027Hi Stephen
I’m not seeing that at line 321 of includes/shortcodes.php.From line 203 I’m seeing
$tax = get_taxonomy( 'event-category' ); $cat_objs = get_terms( 'event-category', array( 'hide_empty' => 0 ) ); if ( $cat_objs ) { $cats = array_combine( wp_list_pluck( $cat_objs, 'slug' ), wp_list_pluck( $cat_objs, 'name' ) ); } else { $cats = array();
What should I be changing?
Many thanks for your help
MadeleineMadeleine ParkynNovember 8, 2018 at 8:25 am #32053What version of Event Organiser Pro are you running?
Stephen HarrisNovember 8, 2018 at 10:14 am #32054Hi Stephen
It’s Version 1.11.15 for Event Organiser Pro
and
Version 3.7.4 for Evetn Organiser
Thanks for following up on this.
Best wishes
MadeleineMadeleine ParkynNovember 14, 2018 at 10:44 am #32101Hi Stephen
I was wondering if you’d had any further thoughts about this?
Many thanks
MadeleineMadeleine ParkynNovember 15, 2018 at 10:02 pm #32123In that case, please try:
case 'event_category': $tax = get_taxonomy( 'event-category' ); $cat_objs = get_terms( 'event-category', array( 'hide_empty' => 0 ) ); $cat_objs = array_filter($cat_objs, function($cat) { $whitelist = array('music', 'adult-outreach', 'education'); return in_array($cat->slug, $whitelist); }); if ( $cat_objs ) { $cats = array_combine( wp_list_pluck( $cat_objs, 'slug' ), wp_list_pluck( $cat_objs, 'name' ) ); } else { $cats = array(); }
(note the added four lines).
$cat_objs = array_filter($cat_objs, function($cat) { $whitelist = array('music', 'adult-outreach', 'education'); return in_array($cat->slug, $whitelist); });
Stephen HarrisNovember 16, 2018 at 5:21 pm #32134Thanks very much Stephen. That has done the trick, now I can choose which categories display on the drop down.
Thank you for your help. Have a good weekend.
Madeleine
Madeleine ParkynJuly 30, 2024 at 3:35 pm #44143Hi Stephen,
I have tried adding this custom code which you suggested back in 2018 to exclude certain categories from the search function but this doesn’t seem to be working for me.
Is there a chance that this needs to be updated?
All the best,
GeorgeGeorge UpsonAugust 4, 2024 at 11:38 pm #44166I think it has changed slightly. Line 321 of
includes/shortcodes.php
is currently:$term_objs = get_terms( $taxonomy->name, array( 'hide_empty' => 0 ) ); if ( $term_objs && ! is_wp_error( $term_objs ) ) { $terms = array_combine( wp_list_pluck( $term_objs, 'slug' ), wp_list_pluck( $term_objs, 'name' ) ); } else { $terms = array(); }
if you modify it so it reads:
$term_objs = get_terms( $taxonomy->name, array( 'hide_empty' => 0 ) ); if ( $taxonomy->name == 'event-category') { $term_objs = array_filter($term_objs, function($term) { $whitelist = array('music', 'adult-outreach', 'education'); return in_array($term->slug, $whitelist); }); } if ( $term_objs && ! is_wp_error( $term_objs ) ) { $terms = array_combine( wp_list_pluck( $term_objs, 'slug' ), wp_list_pluck( $term_objs, 'name' ) ); } else { $terms = array(); }
(i.e. the following has been added after the first line shown)
if ( $taxonomy->name == 'event-category') { $term_objs = array_filter($term_objs, function($term) { $whitelist = array('music', 'adult-outreach', 'education'); return in_array($term->slug, $whitelist); }); }
Stephen Harris -
AuthorPosts