Location Dropdown Event Filter
-
Hi,
Can we have location to be a drop down with predefined locations instead of user typing his location in the Event search filter?
Also, can we catch users location automatically?
-
Hi,
you can customize based on your need search filter.
https://www.wp-eventmanager.com/add-custom-field-in-search-filter/
Thank you.
Hi,
I used the below function code for filtering by city. Now I need to know how to connect this with the auto search field so it shows results based on ‘city’
<?php // Add custom Theme Functions here /** * @snippet WooCommerce Add New Tab @ My Account * @how-to Watch tutorial @ https://businessbloomer.com/?p=19055 * @sourcecode https://businessbloomer.com/?p=21253 * @credits https://github.com/woothemes/woocommerce/wiki/2.6-Tabbed-My-Account-page * @author Rodolfo Melogli * @testedwith WooCommerce 2.6.7 */ // ------------------ // 1. Register new endpoint to use for My Account page // Note: Resave Permalinks or it will give 404 error function bbloomer_add_premium_support_endpoint() { add_rewrite_endpoint( 'premium-support', EP_ROOT | EP_PAGES ); } add_action( 'init', 'bbloomer_add_premium_support_endpoint' ); // ------------------ // 2. Add new query var function bbloomer_premium_support_query_vars( $vars ) { $vars[] = 'premium-support'; return $vars; } add_filter( 'query_vars', 'bbloomer_premium_support_query_vars', 0 ); // ------------------ // 3. Insert the new endpoint into the My Account menu function bbloomer_add_premium_support_link_my_account( $items ) { $items['premium-support'] = 'Event Dashboard'; return $items; } add_filter( 'woocommerce_account_menu_items', 'bbloomer_add_premium_support_link_my_account' ); // ------------------ // 4. Add content to the new endpoint function bbloomer_premium_support_content() { echo '<h3>Event Dashboard</h3><p>Welcome to the WooCommerce support area. As a premium customer, you can submit a ticket should you have any WooCommerce issues with your website, snippets or customization. <i>Please contact your theme/plugin developer for theme/plugin-related support.</i></p>'; echo do_shortcode( ' /* your shortcode here */ ' ); } add_action( 'woocommerce_account_premium-support_endpoint', 'bbloomer_premium_support_content' ); function get_event_ticket_price( $post = null ) { $post = get_post( $post ); if ( $post->post_type !== 'event_listing' ) return; return apply_filters( 'display_event_ticket_price', $post->_event_ticket_price, $post ); } function display_event_ticket_price( $before = '', $after = '', $echo = true, $post = null ) { $event_ticket_price = get_event_ticket_price( $post ); if ( strlen( $event_ticket_price ) == 0 ) return; $event_ticket_price = esc_attr( strip_tags( $event_ticket_price ) ); $event_ticket_price = $before . $event_ticket_price . $after; if ( $echo ) echo $event_ticket_price; else return $event_ticket_price; } add_action('check_admin_referer', 'logout_without_confirm', 10, 2); function logout_without_confirm($action, $result) { /** * Allow logout without confirmation */ if ($action == "log-out" && !isset($_GET['_wpnonce'])) { $redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : 'https://sportsbazaar.org/sportshive/'; $location = str_replace('&', '&', wp_logout_url($redirect_to)); header("Location: $location"); die; } } /* To display the phone number of the Company / Organizer */ function get_event_phone_number( $post = null ) { $post = get_post( $post ); if ( $post->post_type !== 'event_listing' ) return; return apply_filters( 'display_event_phone_number', $post->_phone_number, $post ); } function display_event_phone_number( $before = '', $after = '', $echo = true, $post = null ) { $event_phone_number = get_event_phone_number( $post ); if ( strlen( $event_phone_number ) == 0 ) return; $event_phone_number = esc_attr( strip_tags( $event_phone_number ) ); $event_phone_number = $before . $event_phone_number . $after; if ( $echo ) echo $event_phone_number; else return $event_phone_number; } /** * Adding via filter or you can directly add in template file */ 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' => '_event_city', 'value' => $event_city, ); } } return $query_args; }
This is code for location selection. What changes do I need to make in this?
<!-- Search by location section start --> <div class="col-sm-4"> <label for="search_location"><?php _e( 'Location', 'wp-event-manager' ); ?></label> <input type="text" name="search_location" id="search_location" placeholder="<?php esc_attr_e( 'Choose your City', 'wp-event-manager' ); ?>" value="<?php echo esc_attr( $location ); ?>" /> </div>
sorry the function code is this:
/** * Adding via filter or you can directly add in template file */ 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' => '_event_city', 'value' => $event_city, ); } } return $query_args; }
Hi Arshad,
Above last code will works . What is the issue you are facing ?
I have tested with custom filter it will work fine. If you can explain what is the issue you are facing then i can help you.
Thank you
- The topic ‘Location Dropdown Event Filter’ is closed to new replies.