/**
     * Get listings via ajax
     */
    public function get_listings()
    {
        global $wp_post_types;
        $result = array();
        $search_location = sanitize_text_field(stripslashes($_REQUEST['search_location']));
        $search_keywords = sanitize_text_field(stripslashes($_REQUEST['search_keywords']));
        $search_categories = isset($_REQUEST['search_categories']) ? $_REQUEST['search_categories'] : '';
        $filter_job_types = isset($_REQUEST['filter_job_type']) ? array_filter(array_map('sanitize_title', (array) $_REQUEST['filter_job_type'])) : null;
        $types = get_job_listing_types();
        $post_type_label = $wp_post_types['job_listing']->labels->name;
        $orderby = sanitize_text_field($_REQUEST['orderby']);
        if (is_array($search_categories)) {
            $search_categories = array_filter(array_map('sanitize_text_field', array_map('stripslashes', $search_categories)));
        } else {
            $search_categories = array_filter(array(sanitize_text_field(stripslashes($search_categories))));
        }
        $args = array('search_location' => $search_location, 'search_keywords' => $search_keywords, 'search_categories' => $search_categories, 'job_types' => is_null($filter_job_types) || sizeof($types) === sizeof($filter_job_types) ? '' : $filter_job_types + array(0), 'orderby' => $orderby, 'order' => sanitize_text_field($_REQUEST['order']), 'offset' => (absint($_REQUEST['page']) - 1) * absint($_REQUEST['per_page']), 'posts_per_page' => absint($_REQUEST['per_page']));
        if (isset($_REQUEST['filled']) && ($_REQUEST['filled'] === 'true' || $_REQUEST['filled'] === 'false')) {
            $args['filled'] = $_REQUEST['filled'] === 'true' ? true : false;
        }
        if (isset($_REQUEST['featured']) && ($_REQUEST['featured'] === 'true' || $_REQUEST['featured'] === 'false')) {
            $args['featured'] = $_REQUEST['featured'] === 'true' ? true : false;
            $args['orderby'] = 'featured' === $orderby ? 'date' : $orderby;
        }
        ob_start();
        $jobs = get_job_listings(apply_filters('job_manager_get_listings_args', $args));
        $result['found_jobs'] = false;
        if ($jobs->have_posts()) {
            $result['found_jobs'] = true;
            ?>

			<?php 
            while ($jobs->have_posts()) {
                $jobs->the_post();
                ?>

				<?php 
                get_job_manager_template_part('content', 'job_listing');
                ?>

			<?php 
            }
            ?>

		<?php 
        } else {
            ?>

			<?php 
            get_job_manager_template_part('content', 'no-jobs-found');
            ?>

		<?php 
        }
        $result['html'] = ob_get_clean();
        $result['showing'] = array();
        // Generate 'showing' text
        $showing_types = array();
        $unmatched = false;
        foreach ($types as $type) {
            if (is_array($filter_job_types) && in_array($type->slug, $filter_job_types)) {
                $showing_types[] = $type->name;
            } else {
                $unmatched = true;
            }
        }
        if (sizeof($showing_types) == 1) {
            $result['showing'][] = implode(', ', $showing_types);
        } elseif ($unmatched && $showing_types) {
            $last_type = array_pop($showing_types);
            $result['showing'][] = implode(', ', $showing_types) . " &amp; {$last_type}";
        }
        if ($search_categories) {
            $showing_categories = array();
            foreach ($search_categories as $category) {
                $category_object = get_term_by(is_numeric($category) ? 'id' : 'slug', $category, 'job_listing_category');
                if (!is_wp_error($category_object)) {
                    $showing_categories[] = $category_object->name;
                }
            }
            $result['showing'][] = implode(', ', $showing_categories);
        }
        if ($search_keywords) {
            $result['showing'][] = '&ldquo;' . $search_keywords . '&rdquo;';
        }
        $result['showing'][] = $post_type_label;
        if ($search_location) {
            $result['showing'][] = sprintf(__('located in &ldquo;%s&rdquo;', 'wp-job-manager'), $search_location);
        }
        if (1 === sizeof($result['showing'])) {
            $result['showing_all'] = true;
        }
        $result['showing'] = apply_filters('job_manager_get_listings_custom_filter_text', sprintf(__('Showing all %s', 'wp-job-manager'), implode(' ', $result['showing'])));
        // Generate RSS link
        $result['showing_links'] = job_manager_get_filtered_links(array('filter_job_types' => $filter_job_types, 'search_location' => $search_location, 'search_categories' => $search_categories, 'search_keywords' => $search_keywords));
        // Generate pagination
        if (isset($_REQUEST['show_pagination']) && $_REQUEST['show_pagination'] === 'true') {
            $result['pagination'] = get_job_listing_pagination($jobs->max_num_pages, absint($_REQUEST['page']));
        }
        $result['max_num_pages'] = $jobs->max_num_pages;
        wp_send_json(apply_filters('job_manager_get_listings_result', $result, $jobs));
    }
    /**
     * Get listings via ajax
     */
    public function get_listings()
    {
        global $job_manager, $wpdb;
        $result = array();
        $search_location = sanitize_text_field(stripslashes($_POST['search_location']));
        $search_keywords = sanitize_text_field(stripslashes($_POST['search_keywords']));
        $search_categories = isset($_POST['search_categories']) ? $_POST['search_categories'] : '';
        $filter_job_types = isset($_POST['filter_job_type']) ? array_filter(array_map('sanitize_title', (array) $_POST['filter_job_type'])) : null;
        if (is_array($search_categories)) {
            $search_categories = array_filter(array_map('sanitize_text_field', array_map('stripslashes', $search_categories)));
        } else {
            $search_categories = array_filter(array(sanitize_text_field(stripslashes($search_categories))));
        }
        $args = array('search_location' => $search_location, 'search_keywords' => $search_keywords, 'search_categories' => $search_categories, 'job_types' => is_null($filter_job_types) ? '' : $filter_job_types + array(0), 'orderby' => sanitize_text_field($_POST['orderby']), 'order' => sanitize_text_field($_POST['order']), 'offset' => (absint($_POST['page']) - 1) * absint($_POST['per_page']), 'posts_per_page' => absint($_POST['per_page']), 'show_featured_only' => isset($_POST['show_featured_only']) ? absint($_POST['show_featured_only']) : 0);
        $jobs = get_job_listings(apply_filters('job_manager_get_listings_args', $args));
        $result['found_jobs'] = false;
        ob_start();
        if ($jobs->have_posts()) {
            $result['found_jobs'] = true;
            ?>

			<?php 
            while ($jobs->have_posts()) {
                $jobs->the_post();
                ?>

				<?php 
                get_job_manager_template_part('content', 'job_listing');
                ?>

			<?php 
            }
            ?>

		<?php 
        } else {
            ?>

			<?php 
            get_job_manager_template_part('content', 'no-jobs-found');
            ?>

		<?php 
        }
        $result['html'] = ob_get_clean();
        // Generate 'showing' text
        $types = get_job_listing_types();
        if (sizeof($filter_job_types) > 0 && (sizeof($filter_job_types) !== sizeof($types) || $search_keywords || $search_location || $search_categories || apply_filters('job_manager_get_listings_custom_filter', false))) {
            $showing_types = array();
            $unmatched = false;
            foreach ($types as $type) {
                if (in_array($type->slug, $filter_job_types)) {
                    $showing_types[] = $type->name;
                } else {
                    $unmatched = true;
                }
            }
            if (!$unmatched) {
                $showing_types = '';
            } elseif (sizeof($showing_types) == 1) {
                $showing_types = implode(', ', $showing_types) . ' ';
            } else {
                $last = array_pop($showing_types);
                $showing_types = implode(', ', $showing_types);
                $showing_types .= " &amp; {$last} ";
            }
            $showing_categories = array();
            if ($search_categories) {
                foreach ($search_categories as $category) {
                    if (!is_numeric($category)) {
                        $category_object = get_term_by('slug', $category, 'job_listing_category');
                    }
                    if (is_numeric($category) || is_wp_error($category_object) || !$category_object) {
                        $category_object = get_term_by('id', $category, 'job_listing_category');
                    }
                    if (!is_wp_error($category_object)) {
                        $showing_categories[] = $category_object->name;
                    }
                }
            }
            if ($search_keywords) {
                $showing_jobs = sprintf(__('Showing %s&ldquo;%s&rdquo; %sjobs', 'wp-job-manager'), $showing_types, $search_keywords, implode(', ', $showing_categories));
            } else {
                $showing_jobs = sprintf(__('Showing all %s%sjobs', 'wp-job-manager'), $showing_types, implode(', ', $showing_categories) . ' ');
            }
            $showing_location = $search_location ? sprintf(' ' . __('located in &ldquo;%s&rdquo;', 'wp-job-manager'), $search_location) : '';
            $result['showing'] = apply_filters('job_manager_get_listings_custom_filter_text', $showing_jobs . $showing_location);
        } else {
            $result['showing'] = '';
        }
        // Generate RSS link
        $result['showing_links'] = job_manager_get_filtered_links(array('filter_job_types' => $filter_job_types, 'search_location' => $search_location, 'search_categories' => $search_categories, 'search_keywords' => $search_keywords));
        $result['max_num_pages'] = $jobs->max_num_pages;
        echo '<!--WPJM-->';
        echo json_encode(apply_filters('job_manager_get_listings_result', $result));
        echo '<!--WPJM_END-->';
        die;
    }