/**
  * Filter post type archive view queries.
  *
  * - Projects and entities are sorted by title.
  * - People are sorted by last name.
  * - Publications are left to a default sort by date.
  * - All posts_per_page limits are bumped to 2000.
  *
  * @param WP_Query $query
  */
 public function filter_query($query)
 {
     if (!$query->is_main_query() || is_admin()) {
         return;
     }
     $post_types = $this->get_object_type_slugs();
     // Avoid paginating without intent by maxing out at 2000 per archive.
     if ($query->is_post_type_archive($post_types)) {
         $query->set('posts_per_page', 2000);
     }
     // Avoid pagination without intent by maxing out at 2000 per taxonomy archive.
     if ($query->is_tax($this->entity_type_taxonomy) || $query->is_tax($this->topics_taxonomy)) {
         $query->set('posts_per_page', 2000);
     }
     // Entities and projects are sorted by their titles in archive views.
     if ($query->is_tax($this->topics_taxonomy) || $query->is_tax($this->entity_type_taxonomy) || $query->is_post_type_archive($this->entity_content_type) || $query->is_post_type_archive($this->project_content_type)) {
         $query->set('orderby', 'title');
         $query->set('order', 'ASC');
     }
     // People are sorted by their last names in archive views.
     if ($query->is_post_type_archive($post_types) && $query->is_post_type_archive($this->people_content_type)) {
         $query->set('meta_key', '_wsuwp_uc_person_last_name');
         $query->set('orderby', 'meta_value');
         $query->set('order', 'ASC');
     }
 }
示例#2
0
 /**
  * Hook into the_posts to do the main product query if needed - relevanssi compatibility
  *
  * @access public
  * @param array $posts
  * @param WP_Query|bool $query (default: false)
  * @return array
  */
 public function the_posts($posts, $query = false)
 {
     // Abort if there's no query
     if (!$query) {
         return $posts;
     }
     // Abort if we're not filtering posts
     if (empty($this->post__in)) {
         return $posts;
     }
     // Abort if this query has already been done
     if (!empty($query->wc_query)) {
         return $posts;
     }
     // Abort if this isn't a search query
     if (empty($query->query_vars["s"])) {
         return $posts;
     }
     // Abort if we're not on a post type archive/product taxonomy
     if (!$query->is_post_type_archive('product') && !$query->is_tax(get_object_taxonomies('product'))) {
         return $posts;
     }
     $filtered_posts = array();
     $queried_post_ids = array();
     foreach ($posts as $post) {
         if (in_array($post->ID, $this->post__in)) {
             $filtered_posts[] = $post;
             $queried_post_ids[] = $post->ID;
         }
     }
     $query->posts = $filtered_posts;
     $query->post_count = count($filtered_posts);
     // Ensure filters are set
     $this->unfiltered_product_ids = $queried_post_ids;
     $this->filtered_product_ids = $queried_post_ids;
     if (sizeof($this->layered_nav_post__in) > 0) {
         $this->layered_nav_product_ids = array_intersect($this->unfiltered_product_ids, $this->layered_nav_post__in);
     } else {
         $this->layered_nav_product_ids = $this->unfiltered_product_ids;
     }
     return $filtered_posts;
 }
示例#3
0
 /**
  * Alternates the 'posts_per_page' query_var on post type archive pages
  *
  * @param WP_Query $query
  */
 public function alter_post_type_archive($query)
 {
     if (is_admin() || !$query->is_main_query()) {
         return;
     }
     if (!$query->is_home() && !$query->is_post_type_archive()) {
         return;
     }
     $post_type = 'post';
     if (!is_home()) {
         // Get query var
         $post_type = $query->get('post_type');
     }
     if (post_type_supports($post_type, $this->global_feature)) {
         $posts_per_page = (int) g1_get_theme_option('post_type_' . $post_type, 'posts_per_page');
         if (-1 === $posts_per_page || $posts_per_page > 0) {
             $query->set('posts_per_page', $posts_per_page);
         }
     }
 }
 /**
  * used by the layered_nav widget and the price filter widget as they access the global ($all_post_ids)
  * is run on the 'request' filter with highest priority to ensure it runs before main filter_catalog_query
  * gathers all product ID's into a global variable for use elsewhere ($all_post_ids)
  *
  * @param array $request - the array representing the current WordPress request eg. post_type => 'product'
  * @return array - unaltered array of the intial request
  * @since 0.9.9
  **/
 function jigoshop_get_product_ids_in_view($request)
 {
     global $jigoshop_all_post_ids_in_view;
     $jigoshop_all_post_ids_in_view = array();
     $this_query = new WP_Query();
     $this_query->parse_query($request);
     if ($this_query->is_post_type_archive('product') || $this_query->is_tax('product_cat') || $this_query->is_tax('product_tag')) {
         $args = array_merge($this_query->query, array('page_id' => '', 'fields' => 'ids', 'posts_per_page' => -1, 'post_type' => 'product', 'post_status' => 'publish', 'meta_query' => self::meta_query($this_query)));
         $custom_query = get_posts($args);
         $jigoshop_all_post_ids_in_view = array_merge($jigoshop_all_post_ids_in_view, $custom_query);
     }
     $jigoshop_all_post_ids_in_view[] = 0;
     return $request;
 }
 /**
  * Order public Personnel query results alphabetically by last name.
  *
  * @param WP_Query $query
  */
 public function profile_archives($query)
 {
     if (($query->is_post_type_archive($this->personnel_content_type) || is_tax() || is_category() || is_tag()) && $query->is_main_query() && !is_admin()) {
         $query->set('order', 'ASC');
         $query->set('orderby', 'meta_value');
         $query->set('meta_key', '_wsuwp_profile_ad_name_last');
     }
 }
示例#6
0
 /**
  * Filter the child posts from the main query
  *
  * @param  WP_Query $query query object
  * @since  0.4.0
  */
 public function pre_get_posts($query)
 {
     if (!$query->is_main_query()) {
         return;
     }
     if (!$query->is_post_type_archive('gistpen')) {
         return;
     }
     // only top level posts
     $query->set('post_parent', 0);
     return $query;
 }
/**
 * Loads the proper events for the calendar.
 *
 * @since 0.4.0
 * @access private
 *
 * @param WP_Query $wp_query The main query
 */
function jc_archive_event_modify_query($wp_query)
{
    if (is_admin() || !$wp_query->is_post_type_archive('event') || !$wp_query->is_main_query()) {
        return;
    }
    // Get date to use
    $view_month = (int) isset($_REQUEST['cal_month']) ? (int) $_REQUEST['cal_month'] : date_i18n('n');
    $view_year = (int) isset($_REQUEST['cal_year']) ? (int) $_REQUEST['cal_year'] : date_i18n('Y');
    // Get events
    $view_start = "{$view_year}-{$view_month}-01 00:00:00";
    $view_end = "{$view_year}-{$view_month}-31 00:00:00";
    $wp_query->set('posts_per_page', -1);
    $wp_query->set('post_status', array('publish', 'passed'));
    $wp_query->set('orderby', 'meta_value');
    $wp_query->set('order', 'ASC');
    $wp_query->set('hiearchical', false);
    $wp_query->set('ignore_sticky_posts', true);
    $wp_query->set('meta_query', array('relation' => 'OR', array('key' => 'wp_event_calendar_date_time', 'value' => array($view_start, $view_end), 'type' => 'DATETIME', 'compare' => 'BETWEEN'), array('key' => 'wp_event_calendar_end_date_time', 'value' => array($view_start, $view_end), 'type' => 'DATETIME', 'compare' => 'BETWEEN'), array('key' => 'wp_event_calendar_repeat', 'value' => array('10', '100', '1000'), 'compare' => 'IN')));
}