• Resolved jessiemele

    (@jessiemele)


    I followed the tutorial for adding a salary for jobs (https://wpjobmanager.com/document/tutorial-adding-a-salary-field-for-jobs/) and have had success with it except for the last step. I added the salary field in the admin as a select(dropdown) not as an input, as they have in the tutorial b/c that is what my client wants. I can not figure out how to convert this to work with a select instead of an input as they have documented:

    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 'upto20' :
                    $query_args['meta_query'][] = array(
                        'key'     => '_job_salary',
                        'value'   => '20000',
                        'compare' => '<',
                        'type'    => 'NUMERIC'
                    );
                break;
                case 'over60' :
                    $query_args['meta_query'][] = array(
                        'key'     => '_job_salary',
                        'value'   => '60000',
                        'compare' => '>=',
                        'type'    => 'NUMERIC'
                    );
                break;
                default :
                    $query_args['meta_query'][] = array(
                        'key'     => '_job_salary',
                        'value'   => array_map( 'absint', explode( '-', $selected_range ) ),
                        'compare' => 'BETWEEN',
                        'type'    => 'NUMERIC'
                    );
                break;
            }
            // This will show the 'reset' link
            add_filter( 'job_manager_get_listings_custom_filter', '__return_true' );
        }
    }
    return $query_args;
    }
Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi @jessiemele,

    I would be glad to help you on this.

    As you said that you followed https://wpjobmanager.com/document/tutorial-adding-a-salary-field-for-jobs/, you will find the way to add the field for backend. And I guess you are saying you don’t need input field link the one in the the link for backend.

    Just a little tweak will work. You can add a new metabox or the plugin provides action hook to add a select field along with other Listing Data. And if you’ve added the field in front end based on the plugin’s support then the meta_key for the price will be _job_salary. You need to save the price as update_post_meta( $post_id, '_job_salary', '123');.

    Here a link to add metabox to posts.
    https://developer.www.ads-software.com/reference/functions/add_meta_box/#user-contributed-notes

    Hope this helps. If anything comes up while doing it the way you want feel free to ask again. Always ready to help.

    Thank you.
    Best Regards.

    Thread Starter jessiemele

    (@jessiemele)

    Hello Alok, thank you for replying but that isn’t quite what I need. I am trying to modify the above code to work with a dropdown and not an input.

    @jessiemele, the above code that you’ve shared is for filtering (search query) purpose from front end.

    Do you want a select drop down on front end for search purpose and use the field value in above code? If that is what you want then, it is exactly in the Wp Job Manager plugin support link that you have shared.

    Or do you want a select drop down field in backend?
    If you want to add the drop down field in backend listings then, you’ve to follow the above steps I’ve mentioned.

    If you are getting problem in understanding what I said, I will help you get this done by providing example.

    Please specify more clearly.

    Regards.

    Thread Starter jessiemele

    (@jessiemele)

    Hi Alok, It is in the plugin support link but it is for an input value and I need it to be for a select value.

    • This reply was modified 6 years, 10 months ago by jessiemele.

    Hi @jessiemele, Where exactly do you need the select dropdown?

    • #1. Is it in the front end job-submit form?
    • #2. Is it in the search form in front end?
    • #3. Or is it in the backend on each single jobs?

    Thank you.

    Plugin Contributor Jen H. (a11n)

    (@jenhooks)

    Howdy!

    I’m marking this thread as Resolved, since it’s been more than a month since the last reply. If you still need help, definitely let us know here, and mark the thread Unresolved.

    Cheers.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding a salary field for jobs as a dropdown’ is closed to new replies.