php – WP Job Manager – connect filter to an existing widget-field

Question

I’m using WP Job Manager in combination with ListingEasy (theme).

I have made an extra search filter, based on a new custom form field. However, now I want to refer to an existing field, named: working_time_text__day. It is already displayed in a widget on the listing-page, however I’m not sure how to connect to those fields.

Hereby the code with which I created the filter:

/**
 * This code gets your posted field and modifies the job search query
 */
add_filter( 'job_manager_get_listings', 'filter_by_salary_field_query_args', 10, 2 );

function filter_by_salary_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 salary
        if ( ! empty( $form_data['filter_by_salary'] ) ) {
            $selected_range = sanitize_text_field( $form_data['filter_by_salary'] );
            switch ( $selected_range ) {
                case 'vrijdag' :
                    $query_args['meta_query'][] = array(
                        'key'     => '_job_salary',
                        'value'   => 'vrijdag',
                        'compare' => '==',
                    );
                break;
                case 'zaterdag' :
                    $query_args['meta_query'][] = array(
                        'key'     => '_job_salary',
                        'value'   => 'zaterdag',
                        'compare' => '==',
                    );
                break;
                case 'zondag' :
                    $query_args['meta_query'][] = array(
                        'key'     => '_job_salary',
                        'value'   => 'zondag',
                        'compare' => '==',
                    );
                break;
                case 'maandag' :
                    $query_args['meta_query'][] = array(
                        'key'     => '_job_salary',
                        'value'   => 'maandag',
                        'compare' => '==',
                    );
                break;
            }

            // This will show the 'reset' link
            add_filter( 'job_manager_get_listings_custom_filter', '__return_true' );
        }
    }
    return $query_args;
}

In the picture below the script of the side-widget. I want my filter to search on the working_time_text__day, instead of the salary custom field.

enter image description here

To which value I should change the ‘key’ in the query_args?

0
aronverhoeven 2 months 2021-06-12T04:13:08-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse