/** * Queries job listings with certain criteria and returns them * * @access public * @return void */ function get_resumes($args = array()) { global $wpdb, $resume_manager_keyword; $args = wp_parse_args($args, array('search_location' => '', 'search_keywords' => '', 'search_categories' => array(), 'offset' => '', 'posts_per_page' => '-1', 'orderby' => 'date', 'order' => 'DESC', 'featured' => null, 'fields' => 'all')); $query_args = array('post_type' => 'resume', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'offset' => absint($args['offset']), 'posts_per_page' => intval($args['posts_per_page']), 'orderby' => $args['orderby'], 'order' => $args['order'], 'tax_query' => array(), 'meta_query' => array(), 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false, 'fields' => $args['fields']); if ($args['posts_per_page'] < 0) { $query_args['no_found_rows'] = true; } if (!empty($args['search_location'])) { $location_meta_keys = array('geolocation_formatted_address', '_candidate_location', 'geolocation_state_long'); $location_search = array('relation' => 'OR'); foreach ($location_meta_keys as $meta_key) { $location_search[] = array('key' => $meta_key, 'value' => $args['search_location'], 'compare' => 'like'); } $query_args['meta_query'][] = $location_search; } if (!is_null($args['featured'])) { $query_args['meta_query'][] = array('key' => '_featured', 'value' => '1', 'compare' => $args['featured'] ? '=' : '!='); } if (!empty($args['search_categories'])) { $field = is_numeric($args['search_categories'][0]) ? 'term_id' : 'slug'; $operator = 'all' === get_option('resume_manager_category_filter_type', 'all') && sizeof($args['search_categories']) > 1 ? 'AND' : 'IN'; $query_args['tax_query'][] = array('taxonomy' => 'resume_category', 'field' => $field, 'terms' => array_values($args['search_categories']), 'include_children' => $operator !== 'AND', 'operator' => $operator); } if ('featured' === $args['orderby']) { $query_args['orderby'] = array('menu_order' => 'ASC', 'title' => 'DESC'); } if ($resume_manager_keyword = sanitize_text_field($args['search_keywords'])) { $query_args['_keyword'] = $resume_manager_keyword; // Does nothing but needed for unique hash add_filter('posts_clauses', 'get_resumes_keyword_search'); } $query_args = apply_filters('resume_manager_get_resumes', $query_args, $args); if (empty($query_args['meta_query'])) { unset($query_args['meta_query']); } if (empty($query_args['tax_query'])) { unset($query_args['tax_query']); } // Filter args $query_args = apply_filters('get_resumes_query_args', $query_args, $args); // Generate hash $to_hash = defined('ICL_LANGUAGE_CODE') ? json_encode($query_args) . ICL_LANGUAGE_CODE : json_encode($query_args); $query_args_hash = 'jm_' . md5($to_hash) . WP_Job_Manager_Cache_Helper::get_transient_version('get_resume_listings'); do_action('before_get_job_listings', $query_args, $args); if (false === ($result = get_transient($query_args_hash))) { $result = new WP_Query($query_args); set_transient($query_args_hash, $result, DAY_IN_SECONDS * 30); } do_action('after_get_resumes', $query_args, $args); remove_filter('posts_clauses', 'get_resumes_keyword_search'); return $result; }
/** * Based on wp_dropdown_categories, with the exception of supporting multiple selected categories. * @see wp_dropdown_categories */ function job_manager_dropdown_categories($args = '') { $defaults = array('orderby' => 'id', 'order' => 'ASC', 'show_count' => 0, 'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 0, 'name' => 'cat', 'id' => '', 'class' => 'job-manager-category-dropdown ' . (is_rtl() ? 'chosen-rtl' : ''), 'depth' => 0, 'taxonomy' => 'job_listing_category', 'value' => 'id', 'multiple' => true, 'show_option_all' => false, 'placeholder' => __('Choose a category…', 'wp-job-manager'), 'no_results_text' => __('No results match', 'wp-job-manager'), 'multiple_text' => __('Select Some Options', 'wp-job-manager')); $r = wp_parse_args($args, $defaults); if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { $r['pad_counts'] = true; } extract($r); // Store in a transient to help sites with many cats $categories_hash = 'jm_cats_' . md5(json_encode($r) . WP_Job_Manager_Cache_Helper::get_transient_version('jm_get_' . $r['taxonomy'])); $categories = get_transient($categories_hash); if (empty($categories)) { $categories = get_terms($taxonomy, array('orderby' => $r['orderby'], 'order' => $r['order'], 'hide_empty' => $r['hide_empty'], 'child_of' => $r['child_of'], 'exclude' => $r['exclude'], 'hierarchical' => $r['hierarchical'])); set_transient($categories_hash, $categories, DAY_IN_SECONDS * 30); } $name = esc_attr($name); $class = esc_attr($class); $id = $id ? esc_attr($id) : $name; $output = "<select name='" . esc_attr($name) . "[]' id='" . esc_attr($id) . "' class='" . esc_attr($class) . "' " . ($multiple ? "multiple='multiple'" : '') . " data-placeholder='" . esc_attr($placeholder) . "' data-no_results_text='" . esc_attr($no_results_text) . "' data-multiple_text='" . esc_attr($multiple_text) . "'>\n"; if ($show_option_all) { $output .= '<option value="">' . esc_html($show_option_all) . '</option>'; } if (!empty($categories)) { include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-category-walker.php'; $walker = new WP_Job_Manager_Category_Walker(); if ($hierarchical) { $depth = $r['depth']; // Walk the full depth. } else { $depth = -1; // Flat. } $output .= $walker->walk($categories, $depth, $r); } $output .= "</select>\n"; if ($echo) { echo $output; } return $output; }
/** * Flush the cache */ public function resume_manager_my_resume_do_action($action) { WP_Job_Manager_Cache_Helper::get_transient_version('get_resume_listings', true); }
/** * When the transient version increases, this is used to remove all past transients to avoid filling the DB. * * Note; this only works on transients appended with the transient version, and when object caching is not being used. */ private static function delete_version_transients($version) { if (!wp_using_ext_object_cache() && !empty($version)) { global $wpdb; $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->options} WHERE option_name LIKE %s;", "\\_transient\\_%" . $version)); } } /** * Clear expired transients */ public static function clear_expired_transients() { global $wpdb; if (!wp_using_ext_object_cache() && !defined('WP_SETUP_CONFIG') && !defined('WP_INSTALLING')) { $limit = apply_filters('job_manager_clear_expired_transients_limit', 500); $sql = "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b\n\t\t\t\tWHERE a.option_name LIKE %s\n\t\t\t\tAND a.option_name NOT LIKE %s\n\t\t\t\tAND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )\n\t\t\t\tAND b.option_value < %d\n\t\t\t\tLIMIT %d;"; $affected = $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_transient_jm_') . '%', $wpdb->esc_like('_transient_timeout_jm_') . '%', time(), $limit)); // If affected rows is equal to limit, there are more rows to delete. Delete in 10 secs. if ($affected === $limit) { wp_schedule_single_event(time() + 10, 'job_manager_clear_expired_transients'); } } } } WP_Job_Manager_Cache_Helper::init();
/** * Queries job listings with certain criteria and returns them * * @access public * @return void */ function get_job_listings($args = array()) { global $wpdb, $job_manager_keyword; $args = wp_parse_args($args, array('search_location' => '', 'search_keywords' => '', 'search_categories' => array(), 'job_types' => array(), 'offset' => 0, 'posts_per_page' => 20, 'orderby' => 'date', 'order' => 'DESC', 'featured' => null, 'filled' => null, 'fields' => 'all')); $query_args = array('post_type' => $args['post_type'], 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'offset' => absint($args['offset']), 'posts_per_page' => intval($args['posts_per_page']), 'orderby' => $args['orderby'], 'order' => $args['order'], 'tax_query' => array(), 'meta_query' => array(), 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false, 'fields' => $args['fields']); if ($args['posts_per_page'] < 0) { $query_args['no_found_rows'] = true; } if (!empty($args['search_location'])) { $location_meta_keys = array('geolocation_formatted_address', '_job_location', 'geolocation_state_long'); $location_search = array('relation' => 'OR'); foreach ($location_meta_keys as $meta_key) { $location_search[] = array('key' => $meta_key, 'value' => $args['search_location'], 'compare' => 'like'); } $query_args['meta_query'][] = $location_search; } if (!is_null($args['featured'])) { $query_args['meta_query'][] = array('key' => '_featured', 'value' => '1', 'compare' => $args['featured'] ? '=' : '!='); } if (!is_null($args['filled']) || 1 === absint(get_option('job_manager_hide_filled_positions'))) { $query_args['meta_query'][] = array('key' => '_filled', 'value' => '1', 'compare' => $args['filled'] ? '=' : '!='); } if (!empty($args['job_types'])) { $query_args['tax_query'][] = array('taxonomy' => 'job_listing_type', 'field' => 'slug', 'terms' => $args['job_types']); } if (!empty($args['search_categories'])) { $field = is_numeric($args['search_categories'][0]) ? 'term_id' : 'slug'; $operator = 'all' === get_option('job_manager_category_filter_type', 'all') && sizeof($args['search_categories']) > 1 ? 'AND' : 'IN'; $query_args['tax_query'][] = array('taxonomy' => 'job_listing_category', 'field' => $field, 'terms' => array_values($args['search_categories']), 'include_children' => $operator !== 'AND', 'operator' => $operator); } if ('featured' === $args['orderby']) { $query_args['orderby'] = array('menu_order' => 'ASC', 'date' => 'DESC'); } if ($args['year']) { $query_args['year'] = $args['year']; } if ($args['monthnum']) { $query_args['monthnum'] = $args['monthnum']; } if ($args['day']) { $query_args['day'] = $args['day']; } if ($args['w']) { $query_args['w'] = $args['w']; } if ($args['meta_query']) { $query_args['meta_query'] = $args['meta_query']; } $job_manager_keyword = sanitize_text_field($args['search_keywords']); if (!empty($job_manager_keyword) && strlen($job_manager_keyword) >= apply_filters('job_manager_get_listings_keyword_length_threshold', 2)) { $query_args['_keyword'] = $job_manager_keyword; // Does nothing but needed for unique hash add_filter('posts_clauses', 'get_job_listings_keyword_search'); } $query_args = apply_filters('job_manager_get_listings', $query_args, $args); if (empty($query_args['meta_query'])) { unset($query_args['meta_query']); } if (empty($query_args['tax_query'])) { unset($query_args['tax_query']); } // Polylang LANG arg if (function_exists('pll_current_language')) { $query_args['lang'] = pll_current_language(); } // Filter args $query_args = apply_filters('get_job_listings_query_args', $query_args, $args); // Generate hash $to_hash = json_encode($query_args) . apply_filters('wpml_current_language', ''); $query_args_hash = 'jm_' . md5($to_hash) . WP_Job_Manager_Cache_Helper::get_transient_version('get_job_listings'); do_action('before_get_job_listings', $query_args, $args); // if ( false === ( $result = get_transient( $query_args_hash ) ) ) { // echo '<pre>'; // print_r($query_args); $result = new WP_Query($query_args); set_transient($query_args_hash, $result, DAY_IN_SECONDS * 30); // } do_action('after_get_job_listings', $query_args, $args); remove_filter('posts_clauses', 'get_job_listings_keyword_search'); //echo $result->request; return $result; }