Events by
-
Hellon
is there a filter to add to the [events] shortcode to display events by organizer/author ? (I have the Organizers add-ons installed on my website )
If the answer is no, is there an other way to do so ?
Regards,
Jeanne
-
Hello @jeannefructiweb
Please add this code into your child theme functions.php file.
add_filter( 'event_manager_output_events_defaults', 'custom_event_manager_organizer_args' ); function custom_event_manager_organizer_args($arg){ $arg['organizer_name'] = ''; return $arg; } /** * Adding via filter or you can directly add in template file */ add_action( 'event_manager_event_filters_search_events_end', 'filter_by_oragnizer_field' ); function filter_by_oragnizer_field( $atts ) { if($atts['organizer_name']){ ?> <input type="hidden" name="filter_by_organizer_name" id="filter_by_organizer_name" value="<?=$atts['organizer_name'];?>"> <?php } } /** * This code gets your posted field and modifies the event search query */ add_filter( 'event_manager_get_listings', 'filter_by_organizer_field_query_args', 10, 2 ); function filter_by_organizer_field_query_args( $query_args, $args ) { if ( isset( $_POST['form_data'] ) ) { parse_str( $_POST['form_data'], $form_data ); // If this is set, we are filtering by country if ( ! empty( $form_data['filter_by_organizer_name'] ) ) { $event_organizer = sanitize_text_field( $form_data['filter_by_organizer_name'] ); $query_args['meta_query'][] = array( 'key' => '_organizer_name', 'value' => $event_organizer, ); } } return $query_args; }And you need to pass organizer name into your shortcode, like this :
[events organizer_name=”YOUR ORGANIZER NAME VALUE”]Thank you.
Thank you for your answer,
What would be perfect would be the same code but to display events by author, i tried editing your code but couldn’t figured out how to do this…
and the shortcode would be something like [events author_name=”AUTHOR NAME VALUE”],
Can you help me ?Hii @jeannefructiweb
If you want to user [events author_name=”AUTHOR NAME VALUE”] shortcode, then You just need to change “oraganizer_name” to “author_name”.
add_filter( 'event_manager_output_events_defaults', 'custom_event_manager_auther_args' ); function custom_event_manager_auther_args($arg){ $arg['author_name'] = ''; return $arg; } /** * Adding via filter or you can directly add in template file */ add_action( 'event_manager_event_filters_search_events_end', 'filter_by_author_field' ); function filter_by_author_field( $atts ) { if($atts['author_name']){ ?> <input type="hidden" name="filter_by_author_name" id="filter_by_author_name" value="<?=$atts['author_name'];?>"> <?php } } /** * This code gets your posted field and modifies the event search query */ add_filter( 'event_manager_get_listings', 'filter_by_author_field_query_args', 10, 2 ); function filter_by_author_field_query_args( $query_args, $args ) { if ( isset( $_POST['form_data'] ) ) { parse_str( $_POST['form_data'], $form_data ); // If this is set, we are filtering by country if ( ! empty( $form_data['filter_by_author_name'] ) ) { $event_author = sanitize_text_field( $form_data['filter_by_author_name'] ); $query_args['meta_query'][] = array( 'key' => 'author_name', 'value' => $event_author, ); } } return $query_args; }Thank You.
This look fine to me but it doesn’t work, “There are no events matching your search.” ?…
Hello @jeannefructiweb
NOTE : For this feature, you need to set default author(admin) as per the code below. If the author not found which you given in your shortcode [events], then it will show admin(author) events.
You need to change this function for your requirement :
/** * This code gets your posted field and modifies the event search query */ add_filter( 'event_manager_get_listings', 'filter_by_author_field_query_args', 10, 2 ); function filter_by_author_field_query_args( $query_args, $args ) { if ( isset( $_POST['form_data'] ) ) { parse_str( $_POST['form_data'], $form_data ); // If this is set, we are filtering by country if ( ! empty( $form_data['filter_by_author_name'] ) ) { $event_author = sanitize_text_field( $form_data['filter_by_author_name'] ); $the_user = get_user_by('login', $event_author); //If author name not found then you have to set default author if(empty($the_user)){ //set your default autherr name here $the_user_id = 1; }else{ $the_user_id = $the_user->ID; } $query_args['author'] = $the_user_id; } } return $query_args; }Thank You
Hello,
thank you very much for your answer, it worked perfectly !
Is there a way to do the same things with the [events_calendar] shortcode ?
Something like [events_calendar author_name=”AUTHOR NAME VALUE”] ?Hello @jeannefructiweb ,
To apply [events_calendar author_name=”AUTHOR NAME VALUE”] in event calendar shortcode, you need to customize as per above code with your developer help.
Thank You.
The topic ‘Events by’ is closed to new replies.