• Resolved maxcanzonieri

    (@maxcanzonieri)


    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_erogazione

    and 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]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter maxcanzonieri

    (@maxcanzonieri)

    Hello, any updates about my question?

    Hi @maxcanzonieri

    You don’t need to print the query arguments. You need to pring the meta key you have given to field. Use get_post_meta function to output the value of custom field.

    Thank you

    Thread Starter maxcanzonieri

    (@maxcanzonieri)

    Can you help me with this? Can you show me how to print to see the result?

    thanks

    Thread Starter maxcanzonieri

    (@maxcanzonieri)

    Hello Hitesh,

    the problem is not is I print the meta_key. Even if I print it I don’t fix the problem. I have to show the results on the page and I have to understand if some things I did are wrong or not. I can give to you the website access if is necessary but please for me it’s important to fix this problem

    I’m waiting for your reply, best regards
    Massimiliano

    Thread Starter maxcanzonieri

    (@maxcanzonieri)

    Hello, I discovered a problem with your filter.

    If I create a field “select multiple” and use the filter there is an error and no results appears, otherwise, if I create a simple select option the filter work well. So, how I can fix it?

    Hi @maxcanzonieri

    We have discussed this over support Ticket.

    Regards,
    Priya

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Custom Filter doesn’t work’ is closed to new replies.