Custom Filter doesn’t work
-
I’m using the wp event manager plugin on WordPress and I’m trying to custom it. I created some custom fields in the back-end _event_modalita_erogazione. This field was compiled in every event created in the back-end.
I added the code for a new filter in the functions.php file as the official guideline.
// ADD FILTER /** * Adding via filter or you can directly add in a template file */ add_action( 'event_manager_event_filters_search_events_end', 'filter_by_modalita_erogazione_field' ); function filter_by_modalita_erogazione_field() { ?> <div class="wpem-row"> <div class="wpem-col"> <div class="wpem-form-group"> <div class="search_event_types"> <label for="search_event_types" class="wpem-form-label"><?php _e( 'Erogazione', 'event_manager' ); ?></label> <select name="filter_by_erogazione" class="event-manager-filter"> <option value=""><?php _e( 'Erogazione', 'event_manager' ); ?></option> <option value="aula"><?php _e( 'Aula', 'event_manager' ); ?></option> <option value="videoconferanza"><?php _e( 'Videoconferenza', 'event_manager' ); ?></option> <option value="e-learning"><?php _e( 'E-learning', 'event_manager' ); ?></option> </select> </div> </div> </div> </div> <?php } /** * This code gets your posted field and modifies the event search query */ add_filter( 'event_manager_get_listings', 'filter_by_state_field_query_args', 10, 2 ); function filter_by_state_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 modalita erogazione. if ( ! empty( $form_data['filter_by_erogazione'] ) ) { $event_modalita_erogazione = sanitize_text_field( $form_data['filter_by_erogazione'] ); var_dump( $event_modalita_erogazione ); $query_args['meta_query'][] = array( 'key' => '_modalita_erogazione', 'value' => $event_modalita_erogazione, ); } } var_dump( $query_args ); return $query_args; }I added on the back-end the input field:
Etichetta Tipo Placeholder / Opzioni Meta Key
Modalità di erogazione multiple selection aula videoconferenza e-learning _event_modalita_erogazioneand in the DB I have the association of the event with this data, 8 row in total
| meta key| data | |:—- |:——:| | _event_modalita_erogazione | a:2:{i:0;s:4:”aula”;i:1;s:15:”videoconferenza”;} | | _event_modalita_erogazione | a:2:{i:0;s:4:”aula”;i:1;s:15:”videoconferenza”;} | | _event_modalita_erogazione | a:2:{i:0;s:4:”aula”;i:1;s:15:”videoconferenza”;} | | _event_modalita_erogazione | a:2:{i:0;s:4:”aula”;i:1;s:15:”videoconferenza”;} | | _event_modalita_erogazione | a:2:{i:0;s:4:”aula”;i:1;s:15:”videoconferenza”;} | | _event_modalita_erogazione | a:2:{i:0;s:4:”aula”;i:1;s:15:”videoconferenza”;} | | _event_modalita_erogazione | a:2:{i:0;s:4:”aula”;i:1;s:15:”videoconferenza”;} | | _event_modalita_erogazione | a:2:{i:0;s:4:”aula”;i:1;s:15:”videoconferenza”;} |
but when I tried to use the filter and select “Erogazione->Videoconferenza” the page reported to me “no elements found”.
The debug print is
string(15) "videoconferanza" array(13) { ["post_type"]=> string(13) "event_listing" ["post_status"]=> string(7) "publish" ["ignore_sticky_posts"]=> int(1) ["offset"]=> int(0) ["posts_per_page"]=> int(10) ["orderby"]=> string(10) "meta_value" ["order"]=> string(3) "ASC" ["tax_query"]=> array(0) { } ["meta_query"]=> array(1) { [0]=> array(2) { ["key"]=> string(20) "_modalita_erogazione" ["value"]=> string(15) "videoconferanza" } } ["update_post_term_cache"]=> bool(false) ["update_post_meta_cache"]=> bool(false) ["cache_results"]=> bool(false) ["fields"]=> string(3) "all" }The page I need help with: [log in to see the link]
The topic ‘Custom Filter doesn’t work’ is closed to new replies.