/** * output_jobs function. * * @access public * @param mixed $args * @return void */ public function output_jobs($atts) { ob_start(); extract($atts = shortcode_atts(apply_filters('job_manager_output_jobs_defaults', array('per_page' => get_option('job_manager_per_page'), 'orderby' => 'featured', 'order' => 'DESC', 'show_filters' => true, 'show_categories' => true, 'show_category_multiselect' => get_option('job_manager_enable_default_category_multiselect', false), 'show_pagination' => false, 'show_more' => true, 'categories' => '', 'job_types' => '', 'featured' => null, 'filled' => null, 'location' => '', 'keywords' => '', 'selected_category' => '', 'selected_job_types' => implode(',', array_values(get_job_listing_types('id=>slug'))))), $atts)); if (!get_option('job_manager_enable_categories')) { $show_categories = false; } // String and bool handling $show_filters = $this->string_to_bool($show_filters); $show_categories = $this->string_to_bool($show_categories); $show_category_multiselect = $this->string_to_bool($show_category_multiselect); $show_more = $this->string_to_bool($show_more); $show_pagination = $this->string_to_bool($show_pagination); if (!is_null($featured)) { $featured = is_bool($featured) && $featured || in_array($featured, array('1', 'true', 'yes')) ? true : false; } if (!is_null($filled)) { $filled = is_bool($filled) && $filled || in_array($filled, array('1', 'true', 'yes')) ? true : false; } // Array handling $categories = is_array($categories) ? $categories : array_filter(array_map('trim', explode(',', $categories))); $job_types = is_array($job_types) ? $job_types : array_filter(array_map('trim', explode(',', $job_types))); $selected_job_types = is_array($selected_job_types) ? $selected_job_types : array_filter(array_map('trim', explode(',', $selected_job_types))); // Get keywords and location from querystring if set if (!empty($_GET['search_keywords'])) { $keywords = sanitize_text_field($_GET['search_keywords']); } if (!empty($_GET['search_location'])) { $location = sanitize_text_field($_GET['search_location']); } if (!empty($_GET['search_category'])) { $selected_category = sanitize_text_field($_GET['search_category']); } if ($show_filters) { get_job_manager_template('job-filters.php', array('per_page' => $per_page, 'orderby' => $orderby, 'order' => $order, 'show_categories' => $show_categories, 'categories' => $categories, 'selected_category' => $selected_category, 'job_types' => $job_types, 'atts' => $atts, 'location' => $location, 'keywords' => $keywords, 'selected_job_types' => $selected_job_types, 'show_category_multiselect' => $show_category_multiselect)); get_job_manager_template('job-listings-start.php'); get_job_manager_template('job-listings-end.php'); if (!$show_pagination && $show_more) { echo '<a class="load_more_jobs" href="#" style="display:none;"><strong>' . __('Load more listings', 'wp-job-manager') . '</strong></a>'; } } else { $jobs = get_job_listings(apply_filters('job_manager_output_jobs_args', array('search_location' => $location, 'search_keywords' => $keywords, 'search_categories' => $categories, 'job_types' => $job_types, 'orderby' => $orderby, 'order' => $order, 'posts_per_page' => $per_page, 'featured' => $featured, 'filled' => $filled))); if ($jobs->have_posts()) { ?> <?php get_job_manager_template('job-listings-start.php'); ?> <?php while ($jobs->have_posts()) { $jobs->the_post(); ?> <?php get_job_manager_template_part('content', 'job_listing'); ?> <?php } ?> <?php get_job_manager_template('job-listings-end.php'); ?> <?php if ($jobs->found_posts > $per_page && $show_more) { ?> <?php wp_enqueue_script('wp-job-manager-ajax-filters'); ?> <?php if ($show_pagination) { ?> <?php echo get_job_listing_pagination($jobs->max_num_pages); ?> <?php } else { ?> <a class="load_more_jobs" href="#"><strong><?php _e('Load more listings', 'wp-job-manager'); ?> </strong></a> <?php } ?> <?php } ?> <?php } else { do_action('job_manager_output_jobs_no_results'); } wp_reset_postdata(); } $data_attributes_string = ''; $data_attributes = array('location' => $location, 'keywords' => $keywords, 'show_filters' => $show_filters ? 'true' : 'false', 'show_pagination' => $show_pagination ? 'true' : 'false', 'per_page' => $per_page, 'orderby' => $orderby, 'order' => $order, 'categories' => implode(',', $categories)); if (!is_null($featured)) { $data_attributes['featured'] = $featured ? 'true' : 'false'; } if (!is_null($filled)) { $data_attributes['filled'] = $filled ? 'true' : 'false'; } foreach ($data_attributes as $key => $value) { $data_attributes_string .= 'data-' . esc_attr($key) . '="' . esc_attr($value) . '" '; } $job_listings_output = apply_filters('job_manager_job_listings_output', ob_get_clean()); return '<div class="job_listings" ' . $data_attributes_string . '>' . $job_listings_output . '</div>'; }
function widget($args, $instance) { if ($this->get_cached_widget($args)) { return; } extract($args); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $description = isset($instance['description']) ? esc_attr($instance['description']) : false; $featured = isset($instance['featured']) && 1 == $instance['featured'] ? true : null; $limit = isset($instance['limit']) ? absint($instance['limit']) : 3; $after_title = '<h2 class="home-widget-description">' . $description . '</h2>' . $after_title; $listings = get_job_listings(array('posts_per_page' => $limit, 'featured' => $featured, 'no_found_rows' => true)); if (!$listings->have_posts()) { return; } ob_start(); echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } ?> <ul class="job_listings"> <?php while ($listings->have_posts()) { $listings->the_post(); ?> <?php get_template_part('content', 'job_listing'); ?> <?php } ?> </ul> <?php echo $after_widget; wp_reset_postdata(); $content = ob_get_clean(); echo apply_filters($this->widget_id, $content); $this->cache_widget($args, $content); }
/** * 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) . " & {$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'][] = '“' . $search_keywords . '”'; } $result['showing'][] = $post_type_label; if ($search_location) { $result['showing'][] = sprintf(__('located in “%s”', '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 .= " & {$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“%s” %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 “%s”', '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; }
/** * Template Name: Page: Monthly Listing * * @package Listify */ get_header(); ?> <div id="primary" class="container"> <div class="row content-area"> <main id="main" class="site-main col-md-12 col-sm-12 col-xs-12" role="main"> <?php $today = date('Y-m-d'); $date = date('Y-m-d', strtotime("+30 day")); $listings = get_job_listings(array('no_found_rows' => true, 'post_type' => 'befolio_event', 'orderby' => 'date', 'order' => 'ASC', 'meta_query' => array(array('key' => '_date', 'value' => array($today, $date), 'compare' => 'BETWEEN', 'type' => 'DATE')))); if ($listings->have_posts()) { ?> <ul class="job_listings"> <?php while ($listings->have_posts()) { $listings->the_post(); ?> <?php get_template_part('content', 'job_listing'); ?>
/** * widget function. * * @see WP_Widget * @access public * @param array $args * @param array $instance * @return void */ public function widget($args, $instance) { if ($this->get_cached_widget($args)) { return; } ob_start(); extract($args); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $number = absint($instance['number']); $jobs = get_job_listings(array('posts_per_page' => $number, 'orderby' => 'date', 'order' => 'DESC', 'featured' => true)); if ($jobs->have_posts()) { ?> <?php echo $before_widget; ?> <?php if ($title) { echo $before_title . $title . $after_title; } ?> <ul class="job_listings"> <?php while ($jobs->have_posts()) { $jobs->the_post(); ?> <?php get_job_manager_template_part('content-widget', 'job_listing'); ?> <?php } ?> </ul> <?php echo $after_widget; ?> <?php } else { ?> <?php get_job_manager_template_part('content-widget', 'no-jobs-found'); ?> <?php } wp_reset_postdata(); $content = ob_get_clean(); echo $content; $this->cache_widget($args, $content); }
/** * Match jobs to an alert */ public static function get_matching_jobs($alert, $force) { if (method_exists(__CLASS__, 'filter_' . $alert->alert_frequency) && !$force) { add_filter('posts_where', array(__CLASS__, 'filter_' . $alert->alert_frequency)); } if (taxonomy_exists('job_listing_category')) { $cats = array_filter((array) wp_get_post_terms($alert->ID, 'job_listing_category', array('fields' => 'slugs'))); } else { $cats = ''; } if (taxonomy_exists('job_listing_region')) { $regions = array_filter((array) wp_get_post_terms($alert->ID, 'job_listing_region', array('fields' => 'ids'))); } else { $regions = ''; } $types = array_filter((array) wp_get_post_terms($alert->ID, 'job_listing_type', array('fields' => 'slugs'))); $jobs = get_job_listings(apply_filters('job_manager_alerts_get_job_listings_args', array('search_location' => $alert->alert_location, 'search_keywords' => $alert->alert_keyword, 'search_categories' => sizeof($cats) > 0 ? $cats : '', 'search_region' => $regions, 'job_types' => sizeof($types) > 0 ? $types : '', 'orderby' => 'date', 'order' => 'desc', 'offset' => 0, 'posts_per_page' => 50))); if (method_exists(__CLASS__, 'filter_' . $alert->alert_frequency) && !$force) { remove_filter('posts_where', array(__CLASS__, 'filter_' . $alert->alert_frequency)); } return $jobs; }
/** * Template Name: Page: Today Listing * * @package Listify */ get_header(); ?> <div id="primary" class="container"> <div class="row content-area"> <main id="main" class="site-main col-md-12 col-sm-12 col-xs-12" role="main"> <?php $today = getdate(); $listings = get_job_listings(array('no_found_rows' => true, 'post_type' => 'befolio_event', 'post_status' => 'publish,future', 'year' => $today["year"], 'monthnum' => $today["mon"], 'day' => $today["mday"])); if ($listings->have_posts()) { ?> <ul class="job_listings"> <?php while ($listings->have_posts()) { $listings->the_post(); ?> <?php get_template_part('content', 'job_listing'); ?> <?php }
public function get_listings_by_term() { $limit = isset($this->instance['limit']) ? absint($this->instance['limit']) : 3; $featured = isset($this->instance['featured']) && 1 == $this->instance['featured'] ? true : null; $orderby = isset($this->instance['orderby']) ? $this->instance['orderby'] : 'date'; if (!isset($this->taxonomy)) { $this->taxonomy = isset($this->instance['taxonomy']) ? esc_attr($this->instance['taxonomy']) : 'job_listing_type'; } $this->get_terms(); foreach ($this->terms as $term_id) { $objects = get_objects_in_term($term_id, $this->taxonomy, array('orderby' => $orderby)); if (empty($objects)) { $objects = array(-1); } $_output[$term_id] = get_job_listings(array('posts_per_page' => $limit, 'featured' => $featured, 'orderby' => $orderby, 'no_found_rows' => true, 'post__in' => $objects)); } return $_output; }
/** * output_jobs function. * * @access public * @param mixed $args * @return void */ public function output_jobs($atts) { global $job_manager; ob_start(); extract($atts = shortcode_atts(apply_filters('job_manager_output_jobs_defaults', array('per_page' => get_option('job_manager_per_page'), 'orderby' => 'featured', 'order' => 'DESC', 'show_featured_only' => false, 'show_filters' => true, 'show_categories' => get_option('job_manager_enable_categories'), 'categories' => '', 'job_types' => '', 'location' => '', 'keywords' => '')), $atts)); // String to bool if ($show_filters === 'false') { $show_filters = false; } if ($show_featured_only === 'false') { $show_featured_only = false; } $categories = array_filter(array_map('trim', explode(',', $categories))); $job_types = array_filter(array_map('trim', explode(',', $job_types))); // Get keywords and location from querystring if set if (!empty($_GET['search_keywords'])) { $keywords = sanitize_text_field($_GET['search_keywords']); } if (!empty($_GET['search_location'])) { $location = sanitize_text_field($_GET['search_location']); } if ($show_filters && $show_filters !== 'false') { get_job_manager_template('job-filters.php', array('per_page' => $per_page, 'orderby' => $orderby, 'order' => $order, 'show_categories' => $show_categories, 'categories' => $categories, 'job_types' => $job_types, 'atts' => $atts, 'location' => $location, 'keywords' => $keywords)); ?> <ul class="job_listings"></ul><a class="load_more_jobs" href="#" style="display:none;"><strong><?php _e('Load more job listings', 'wp-job-manager'); ?> </strong></a><?php } else { $jobs = get_job_listings(apply_filters('job_manager_output_jobs_args', array('search_location' => $location, 'search_keywords' => $keywords, 'search_categories' => $categories, 'job_types' => $job_types, 'orderby' => $orderby, 'order' => $order, 'posts_per_page' => $per_page, 'show_featured_only' => $show_featured_only))); if ($jobs->have_posts()) { ?> <ul class="job_listings"> <?php while ($jobs->have_posts()) { $jobs->the_post(); ?> <?php get_job_manager_template_part('content', 'job_listing'); ?> <?php } ?> </ul> <?php if ($jobs->found_posts > $per_page) { ?> <?php wp_enqueue_script('wp-job-manager-ajax-filters'); ?> <a class="load_more_jobs" href="#"><strong><?php _e('Load more job listings', 'wp-job-manager'); ?> </strong></a> <?php } ?> <?php } wp_reset_postdata(); } return '<div class="job_listings" data-location="' . esc_attr($location) . '" data-keywords="' . esc_attr($keywords) . '" data-show_filters="' . ($show_filters ? 1 : 0) . '" data-show_featured_only="' . ($show_featured_only ? 1 : 0) . '" data-per_page="' . esc_attr($per_page) . '" data-orderby="' . esc_attr($orderby) . '" data-order="' . esc_attr($order) . '" data-categories="' . esc_attr(implode(',', $categories)) . '">' . ob_get_clean() . '</div>'; }
/** * Set things up * * @since Jobify 1.0 * * @return void */ public function __construct($args = array()) { $this->jobs = get_job_listings($args); $this->setup_actions(); }