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.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #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
    Madeleine

    Madeleine Parkyn
    #31931

    Hi
    I’d really appreciate some guidance with the query above about excluding certain categories from the displayed search results.

    Many thanks
    Madeleine

    Madeleine Parkyn
    #31960

    Hi 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 Harris
    #31971

    Many thanks Stephen. I’ll give it a go.

    With best wishes
    Madeleine

    Madeleine Parkyn
    #31972

    Hi Stephen

    I’m a bit confused. I asked about catgories, but your reply refers to venues, with category slugs?

    Many thanks
    Madeleine

    Madeleine Parkyn
    #31983

    Sorry, 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 Harris
    #32027

    Hi 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
    Madeleine

    Madeleine Parkyn
    #32053

    What version of Event Organiser Pro are you running?

    Stephen Harris
    #32054

    Hi 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
    Madeleine

    Madeleine Parkyn
    #32101

    Hi Stephen

    I was wondering if you’d had any further thoughts about this?

    Many thanks
    Madeleine

    Madeleine Parkyn
    #32123

    In 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 Harris
    #32134

    Thanks 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 Parkyn
    #44143

    Hi 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,
    George

    George Upson
    #44166

    I 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
Viewing 14 posts - 1 through 14 (of 14 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.