WordPress.org

Forums

Events Manager
[resolved] search form with custom attributes (12 posts)

  1. reinhold_B
    Member
    Posted 8 months ago #

    Hi,

    I added custom attributes to my events and I would like to search for them. I've followed the tutorials on the homepage (http://wp-events-plugin.com/tutorials/creating-a-events-manager-add-on-a-complete-walkthrough/) but also the code of the tutorial does not work.

    add_action('em_template_events_search_form_ddm','my_em_styles_search_form');

    The action never gets triggered. Could it be that this code doesn't work anymore with the latest release?

    Events Manager: 5.5.3.1
    WordPress: 3.9.1

    Thanks a lot for your help!

    https://wordpress.org/plugins/events-manager/

  2. reinhold_B
    Member
    Posted 8 months ago #

    After looking into the code it seems that the hook from the tutorial doesn't exist anymore. ''em_template_events_search_form_header' and 'em_template_events_search_form_footer' are working.

    If the plugin author is reading this I would highly appreciate if the tutorials are at least marked as out-dated. Thx!

  3. caimin_nwl
    NetWebLogic Support
    Posted 8 months ago #

    Can you post the complete code that you're using? That'll give us a chance to test it. Thanks.

  4. reinhold_B
    Member
    Posted 8 months ago #

    I tried to follow http://wp-events-plugin.com/tutorials/adding-custom-event-search-form-fields/

    but instead of

    add_action('em_template_events_search_form_ddm','my_em_styles_search_form');

    I use

    add_action('em_template_events_search_form_header','my_em_styles_search_form');

  5. caimin_nwl
    NetWebLogic Support
    Posted 8 months ago #

    Thanks, I see what you mean. I'll pass this on to get the tutorial updated.

  6. reinhold_B
    Member
    Posted 8 months ago #

    Thank you!

  7. tco9876
    Member
    Posted 8 months ago #

    I'm still not getting this to work, even with abovementioned modification. Should this still be working?

    P.S. the tutorial has not been updated yet

  8. tco9876
    Member
    Posted 8 months ago #

    anyone can help with this?

    Sorry for the bump

  9. reinhold_B
    Member
    Posted 7 months ago #

    tco9876, what are you exactly trying to achieve and what have you tried so far?

  10. tco9876
    Member
    Posted 7 months ago #

    Hi,

    What I want is that users can specify an extra taxonomy when submitting events (choosing from a list of trainers) on the front end page. So every event has one trainer attached to it.

    On the event list page users should be able to search by trainer. So I need an extra drop down list here.

    I've tried the code on this page by gmorley http://wordpress.org/support/topic/plugin-events-manager-searching-by-custom-taxonomy. I pasted the code in functions.php, but I don't get an extra box on my search page. After that I tried your modification, but still without success.

  11. reinhold_B
    Member
    Posted 7 months ago #

    Could you post your code? Have you changed the action name as I've posted it?

  12. tco9876
    Member
    Posted 7 months ago #

    Hey,

    The code I used is a combination of your code and gmorleys code:

    // custom Artist taxonomy for events
    add_action( 'init', 'register_my_taxonomies', 0 );
    
    function register_my_taxonomies() {
    $labels = array(
        'name'                          => 'artists',
        'singular_name'                 => 'artist',
        'search_items'                  => 'Search Artists',
        'popular_items'                 => 'Popular Artists',
        'all_items'                     => 'All Artists',
        'parent_item'                   => 'Parent Artist',
        'edit_item'                     => 'Edit Artist',
        'update_item'                   => 'Update Artist',
        'add_new_item'                  => 'Add New Artist',
        'new_item_name'                 => 'New Artist',
        'separate_items_with_commas'    => 'Separate Artists with commas',
        'add_or_remove_items'           => 'Add or remove Artists',
        'choose_from_most_used'         => 'Choose from most used Artists'
        );
    
    $args = array(
        'label'                         => 'Artists',
        'labels'                        => $labels,
        'public'                        => true,
        'hierarchical'                  => true,
        'show_ui'                       => true,
        'show_in_nav_menus'             => true,
        'args'                          => array( 'orderby' => 'term_order' ),
        'rewrite'                       => array( 'slug' => 'events/artists', 'with_front' => false ),
        'query_var'                     => true
    );
    
    register_taxonomy( 'artists', EM_POST_TYPE_EVENT, $args );
    }
    
    // custom taxonomy search and display
    add_action('em_template_events_search_form_header','artists_search_form');
    function artists_search_form(){
    	$artists = (is_array(get_option('artists'))) ? get_option('artists'):array();
    	?>
    	<!-- START artists Search -->
    	<select name="artist" id="artist_search">
    		<option value="" selected="selected">Artists</option>
    		<?php
    		$taxonomies = array('artists');
    		$args = array('orderby'=>'count','hide_empty'=>true);
    		echo get_terms_dropdown($taxonomies, $args);
    		?>
    	</select>
    	<!-- END artists Search -->
    	<?php
    }
    
    function my_em_artists_event_load($EM_Event){
    	global $wpdb;
    	$EM_Event->artists = $wpdb->get_col("SELECT term_taxonomy_id FROM $wpdb->term_relationships WHERE object_id='{$EM_Event->post_id}'", 0	);
    }
    add_action('em_event','my_em_artists_event_load',1,1);
    
    // And make the search attributes for the shortcode
    add_filter('em_events_get_default_search','my_em_artists_get_default_search',1,2);
    function my_em_artists_get_default_search($searches, $array){
    	if( !empty($array['artist']) ){
    		$searches['artist'] = $array['artist'];
    	}
    	return $searches;
    }
    
    add_filter('em_events_get','my_em_artists_events_get',1,2);
    function my_em_artists_events_get($events, $args){
    	if( !empty($args['artist'])  ){
    		foreach($events as $event_key => $EM_Event){
    			if( !in_array($args['artist'],$EM_Event->artists) ){
    				unset($events[$event_key]);
    			}
    		}
    	}
    	return $events;
    }
    
    function get_terms_dropdown($taxonomies, $args){
    	$myterms = get_terms($taxonomies, $args);
    
    	foreach($myterms as $term){
    		$root_url = get_bloginfo('url');
    		$term_taxonomy=$term->taxonomy;
    		$term_slug=$term->slug;
    		$term_name =$term->name;
    		$value = $term->term_id;
    		$output .="<option value='".$value."'>".$term_name."</option>";
    	}
    
    return $output;
    }

Reply

You must log in to post.

About this Plugin

  • Events Manager
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic