wp job manager custom filter on date

2019-05-29 01:33发布

I am using "wp job manager" and trying to filter/search by start date. It is not working for me here is my code.

add_filter('job_manager_get_listings','filter_by_date_field_query_args', 10, 2);

function filter_by_date_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['start_date'])) {
        $date = sanitize_text_field($form_data['start_date']);
        $start_date = date('Y-m-d',strtotime($date." +15 days"));
        $end_date = date('Y-m-d',strtotime($date." -15 days"));

        $query_args['meta_query'][] = array(
            'key' => 'date',
            'value' => array($start_date, $end_date),
            'compare' => 'BETWEEN',
            'type' => 'DATE',
        );

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

I want to find all the record between given dates. Start Date is my custom company field which is added from admin pannel. Thank You.

0条回答
登录 后发表回答