Problem With custom Filter
-
HI,
Thank you so much for the awesome plugin. I am trying to create a custom filter for city field.
I have create a custom field called city with meta _city.
I have used code from a previous thread
https://ww.wp.xz.cn/support/topic/location-dropdown-event-filter/
But the filtering is not working. Can you please let me know what else I have to make it work.Here is the code
add_action( 'event_manager_event_filters_search_events_end', 'filter_by_city_field' ); function filter_by_city_field() { ?> <div class="search_event_types"> <label for="search_event_types"><?php _e( 'City', 'event_manager' ) ?></label> <select name="filter_by_city" class="event-manager-filter"> <option value=""><?php _e( 'Choose your city', 'event_manager' ); ?></option> <option value="mumbai"><?php _e( 'Mumbai', 'event_manager' ); ?></option> <option value="pune"><?php _e( 'Pune', 'event_manager' ); ?></option> <option value="delhi"><?php _e( 'Delhi', 'event_manager' ); ?></option> </select> </div> <?php } /** * This code gets your posted field and modifies the event search query */ add_filter( 'event_manager_get_listings', 'filter_by_city_field_query_args', 10, 2 ); function filter_by_city_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 city if ( ! empty( $form_data['filter_by_city'] ) ) { $event_city = sanitize_text_field( $form_data['filter_by_city'] ); $query_args['meta_query'][] = array( 'key' => '_city', 'value' => $city, ); } } return $query_args; }The page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Problem With custom Filter’ is closed to new replies.