Add Category to Search Bar

Home Forums Calendar Products Events Calendar PRO Add Category to Search Bar

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1188546
    Felix
    Participant

    Hi,

    I need to have a drop-down with all categories in the regular search bar. I know it can be added as a filter, but that would produce the extra box and make the search more complex than needed.

    How can I add it as a regular field? I have prepared this so far:

    add_filter( 'tribe-events-bar-filters',  'tribe_events_add_category', 1, 1 );
    
    function tribe_events_add_category( $filters ) {
        $filters['tribe-bar-category'] = array(
            'name' => 'tribe-bar-category',
            'caption' => 'Category',
            'html' => ''
        );
    
        return $filters;
    }

    I hope you can help.

    Thanks in advance,
    Felix

    #1188902
    George
    Participant

    This reply is private.

    #1189517

    Hello, I got the same problem. I want to put a category drop down into the searchbar. Can you help me?

    #1189518
    Felix
    Participant

    Hi,

    I managed to integrate a solution, but it only seems to work properly with the “Filter Bar” Plugin active on the page. Please feel free to post a better solution.

    add_filter( 'tribe-events-bar-filters',  'tribe_events_add_category_filter', 1, 1 );
    
    function tribe_events_add_category_filter( $filters ) {
        $args = array(
    	'show_option_all'    => esc_html__( "All", "the-events-calendar" ),
    	'show_option_none'   => '',
    	'option_none_value'  => '-1',
    	'orderby'            => 'ID',
    	'order'              => 'ASC',
    	'show_count'         => 0,
    	'hide_empty'         => 1,
    	'child_of'           => 0,
    	'exclude'            => '',
    	'include'            => '',
    	'echo'               => 0,
    	'selected'           => '-1',
    	'hierarchical'       => 0,
    	'name'               => 'tribe_eventcategory',
    	'id'                 => '',
    	'class'              => '',
    	'depth'              => 0,
    	'tab_index'          => 0,
    	'taxonomy'           => 'tribe_events_cat',
    	'hide_if_empty'      => false,
    	'value_field'	     => 'term_id',
    );
    
    $html = wp_dropdown_categories( $args );
    
        $filters['tribe-bar-category'] = array(
            'name' => 'tribe-bar-category',
            'caption' => esc_html__( 'Category', 'the-events-calendar' ),
            'html' => $html
        );
    
        return $filters;
    }
    #1189531
    George
    Participant

    Hey Deltex,

    I wrote this above to Felix, so will post it here as well:

    We unfortunately cannot provide any assistance with writing custom code, which would be required to pull off what you describe. Our Filter Bar add-on indeed offers the Category filter (which you can choose a few different display options for, by the way, so it doesn’t have to be a big complex checkbox system and can be a simple one-level dropdown instead).

    Other than our Filter Bar add-on, you would have to manually code all of this filter yourself and/or hire a professional developer for assistance. We have a list of great developers here → http://m.tri.be/18k1 (and we have no affiliation with any of these folks–they’re simply some well-respected names in the community that we’ve compiled).

    ☝️ I’m sorry to bear this news, but perhaps the code Felix suggested helps.

    I wish you both the best of luck with these customizations. Open a new thread any time if other issues or questions arise.

    Cheers,
    George

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Add Category to Search Bar’ is closed to new replies.