当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_Query::set方法代码示例

本文整理汇总了PHP中WP_Query::set方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Query::set方法的具体用法?PHP WP_Query::set怎么用?PHP WP_Query::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WP_Query的用法示例。


在下文中一共展示了WP_Query::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: dokan_admin_shop_order_remove_parents

/**
 * Filter all the shop orders to remove child orders
 *
 * @param WP_Query $query
 */
function dokan_admin_shop_order_remove_parents($query)
{
    if ($query->is_main_query() && $query->query['post_type'] == 'shop_order') {
        $query->set('orderby', 'ID');
        $query->set('order', 'DESC');
    }
}
开发者ID:uwitec,项目名称:findgreatmaster,代码行数:12,代码来源:admin-functions.php

示例2: ep_admin_integrate

/**
 * Integrate EP into proper queries
 * 
 * @param  WP_Query $query
 * @since  2.1
 */
function ep_admin_integrate($query)
{
    // Lets make sure this doesn't interfere with the CLI
    if (defined('WP_CLI') && WP_CLI) {
        return;
    }
    if (!$query->is_main_query()) {
        return;
    }
    /**
     * We limit to these post types to not conflict with other modules like WooCommerce
     *
     * @since  2.1
     * @var array
     */
    $post_types = array('post' => 'post', 'page' => 'page');
    $supported_post_types = apply_filters('ep_admin_supported_post_types', $post_types);
    $post_type = $query->get('post_type');
    if (empty($post_type)) {
        $post_type = 'post';
    }
    if (is_array($post_type)) {
        foreach ($post_type as $pt) {
            if (empty($supported_post_types[$pt])) {
                return;
            }
        }
        $query->set('ep_integrate', true);
    } else {
        if (!empty($supported_post_types[$post_type])) {
            $query->set('ep_integrate', true);
        }
    }
}
开发者ID:10up,项目名称:elasticpress,代码行数:40,代码来源:admin.php

示例3: parse_query

 /**
  * Set any query flags
  *
  * @param WP_Query $query
  *
  * @return void
  **/
 public static function parse_query($query)
 {
     // set paged
     if ($query->is_main_query() && isset($_GET['tribe_paged'])) {
         $query->set('paged', $_REQUEST['tribe_paged']);
     }
     // Add tribe events post type to tag queries
     if ($query->is_tag && (array) $query->get('post_type') != array(TribeEvents::POSTTYPE)) {
         $types = $query->get('post_type');
         if (empty($types)) {
             $types = array('post');
         }
         if (is_array($types)) {
             $types[] = TribeEvents::POSTTYPE;
         } else {
             if (is_string($types)) {
                 $types = array($types, TribeEvents::POSTTYPE);
             } else {
                 if ($types != 'any') {
                     $types = array('post', TribeEvents::POSTTYPE);
                 }
             }
         }
         $query->set('post_type', $types);
     }
     $types = !empty($query->query_vars['post_type']) ? (array) $query->query_vars['post_type'] : array();
     // check if any possiblity of this being an event query
     $query->tribe_is_event = in_array(TribeEvents::POSTTYPE, $types) && count($types) < 2 ? true : false;
     $query->tribe_is_multi_posttype = in_array(TribeEvents::POSTTYPE, $types) && count($types) >= 2 || in_array('any', $types) ? true : false;
     if ('default' === $query->get('eventDisplay')) {
         $query->set('eventDisplay', TribeEvents::instance()->default_view());
     }
     // check if any possiblity of this being an event category
     $query->tribe_is_event_category = !empty($query->query_vars[TribeEvents::TAXONOMY]) ? true : false;
     $query->tribe_is_event_venue = in_array(TribeEvents::VENUE_POST_TYPE, $types) ? true : false;
     $query->tribe_is_event_organizer = in_array(TribeEvents::ORGANIZER_POST_TYPE, $types) ? true : false;
     $query->tribe_is_event_query = $query->tribe_is_event || $query->tribe_is_event_category || $query->tribe_is_event_venue || $query->tribe_is_event_organizer ? true : false;
     // move along, this is not the query you are looking for
     // is the query pulling posts from the past
     if ($query->is_main_query() && !empty($_REQUEST['tribe_event_display']) && $_REQUEST['tribe_event_display'] == 'past') {
         $query->tribe_is_past = true;
     } elseif (tribe_is_ajax_view_request() && $query->get('eventDisplay') == 'past') {
         $query->tribe_is_past = true;
     } else {
         $query->tribe_is_past = isset($query->tribe_is_past) ? $query->tribe_is_past : false;
     }
     // never allow 404 on month view
     if ($query->is_main_query() && $query->get('eventDisplay') == 'month' && !$query->is_tax && !$query->tribe_is_event_category) {
         $query->is_post_type_archive = true;
         $query->queried_object = get_post_type_object(TribeEvents::POSTTYPE);
         $query->queried_object_id = 0;
     }
     // check if is_event_query === true and hook filter
     if ($query->tribe_is_event_query) {
         // fixing is_home param
         $query->is_home = !empty($query->query_vars['is_home']) ? $query->query_vars['is_home'] : false;
         do_action('tribe_events_parse_query', $query);
     }
 }
开发者ID:Vinnica,项目名称:theboxerboston.com,代码行数:66,代码来源:tribe-event-query.class.php

示例4: cora_filter_pre_get_posts_reverse_order

/**
 * reversing the order of posts
 *
 * @wp-hook pre_get_posts
 * @param   WP_Query $query
 * @return  WP_Query $query
 */
function cora_filter_pre_get_posts_reverse_order(WP_Query $query)
{
    if ($query->is_main_query()) {
        $query->set('order', 'ASC');
        $query->set('orderby', 'ID');
    }
    return $query;
}
开发者ID:Chrico,项目名称:cora-2014,代码行数:15,代码来源:post.php

示例5: cq_pre_get_posts

 /**
  * pre_get_posts callback
  *
  * @since  1.0.0
  * @param  \WP_Query $q
  * @return void
  */
 public function cq_pre_get_posts(\WP_Query $q)
 {
     // If posts_per_page is -1, then there's no limit set,
     // but we do need a limit to be able to keep the order of UNION sub-queries:
     // @see http://stackoverflow.com/a/7587423/2078474
     if ($q->get('posts_per_page') && '-1' == $q->get('posts_per_page')) {
         $q->set('posts_per_page', 999999);
     }
     // Remove SQL_CALC_FOUND_ROWS from the SQL query:
     $q->set('no_found_rows', 1);
 }
开发者ID:britco,项目名称:wp-combine-queries,代码行数:18,代码来源:EmptyQuery.php

示例6: filter_query_by_active_language

 /**
  * Filter query by active language in admin.
  *
  * @param WP_Query $query
  *
  * @return mixed
  */
 public function filter_query_by_active_language($query)
 {
     global $pagenow;
     if ('nav-menus.php' === $pagenow and $query->query['post_type'] != 'nav_menu_item') {
         $active_lang = FW_Request::GET('fw_translate_to', $this->get_parent()->get_admin_active_language());
         $query->set('meta_key', 'translation_lang');
         $query->set('meta_value', $active_lang);
         $query->set('meta_compare', '=');
     }
     return $query;
 }
开发者ID:albertso,项目名称:Unyson-Translation-Extension,代码行数:18,代码来源:class-fw-extension-translate-menus.php

示例7: snihub_pre_get_posts

/**
 * Pre get posts for customizing the post type
 *
 * @param 					WP_Query $query
 * @return 					void
 */
function snihub_pre_get_posts($query)
{
    if ($query->is_home() && $query->is_main_query()) {
        $query->set('post_type', 'snippet');
        $query->set('meta_query', array(array('key' => 'no_index', 'compare' => 'NOT EXISTS')));
        if (get_query_var('hot_snippets', false)) {
            $query->set('order', 'DESC');
            $query->set('orderby', 'meta_value_num');
            $query->set('meta_key', 'likes');
        }
        if (get_query_var('snippets_by', false)) {
            $query->set('author', get_query_var('snippets_by', '0'));
        }
    }
}
开发者ID:EhsaanF,项目名称:snihub,代码行数:21,代码来源:functions.php

示例8: geodir_modified_query

/**
 * Set geodir page variable in WP_Query instance.
 *
 * @since 1.0.0
 * @package GeoDirectory
 *
 * @param WP_Query $query The WP_Query instance.
 * @return WP_Query
 */
function geodir_modified_query($query)
{
    if ($query->is_main_query() && (geodir_is_page('add-listing') && isset($_REQUEST['pid']) && $_REQUEST['pid'] != '' || geodir_is_page('listing') || geodir_is_page('author') || geodir_is_page('search') || geodir_is_page('detail'))) {
        $query->set('is_geodir_loop', true);
    }
    return $query;
}
开发者ID:bangjojo,项目名称:wp,代码行数:16,代码来源:listing_filters.php

示例9: media_list_table_query

 /**
  * Media List:
  * Do the same as ^^ but for the list view.
  *
  * @param WP_Query $query
  *
  * @return array
  */
 public function media_list_table_query($query)
 {
     if (is_admin() && $query->is_main_query() && 'upload' === get_current_screen()->id) {
         $meta_query = $this->add_status_check_to_meta_query($query->get('meta_query'));
         $query->set('meta_query', $meta_query);
     }
 }
开发者ID:automattic,项目名称:jetpack,代码行数:15,代码来源:class.videopress-media-library.php

示例10: limitPostsToUser

 /**
  * Limits posts that users see to their own
  *
  * @param WP_Query $query The query object
  * @return WP_Query
  */
 public function limitPostsToUser($query)
 {
     if ($query->is_admin) {
         global $user_ID;
         $query->set('author', $user_ID);
     }
     return $query;
 }
开发者ID:spiff888,项目名称:rockharbor,代码行数:14,代码来源:roles.php

示例11: pmc_eve_query_category

/**
 * Remove the featured category on the home page main query
 * @param WP_Query $query
 * @since 1.2
 */
function pmc_eve_query_category($query)
{
    if ($query->is_home() && $query->is_main_query()) {
        $cat = get_category_by_slug('featured');
        if ($cat) {
            $query->set('cat', '-' . $cat->term_id);
        }
    }
}
开发者ID:priscillamc,项目名称:pmc-eve,代码行数:14,代码来源:extras.php

示例12: jc_event_category_frontend_fix

/**
 * For some reason, wp_query does not have the post_type set by default on a frontend tax query for custom post types.
 *
 * @since 1.3.0
 * @access private
 *
 * @param WP_Query $wp_query
 */
function jc_event_category_frontend_fix($wp_query)
{
    if ($wp_query->is_main_query()) {
        if ($wp_query->is_tax) {
            $post_type = get_query_var('post_type');
            if (!$post_type) {
                $post_type = array('post', 'event');
                $wp_query->set('post_type', $post_type);
            }
        }
    }
}
开发者ID:JacksonCollege,项目名称:jc-theme-2015,代码行数:20,代码来源:events.php

示例13: pre_get_posts

 /**
  * フックで表示するレコードに変更があれば変更
  *
  * @param WP_Query $wp_query
  */
 public function pre_get_posts($wp_query)
 {
     if ($wp_query->is_main_query()) {
         $post_type = $wp_query->get('post_type');
         $args = apply_filters('mwform_get_inquiry_data_args-' . $post_type, array());
         if (!empty($args) && is_array($args)) {
             foreach ($args as $key => $value) {
                 $wp_query->set($key, $value);
             }
         }
     }
 }
开发者ID:kuck1u,项目名称:mw-wp-form,代码行数:17,代码来源:class.contact-data-list.php

示例14: action_pre_get_posts

 /**
  * Action pre_get_posts
  *
  * Sort speaking gigs by the appropriate columns.
  *
  * @since 3.1.0
  *
  * @param \WP_Query $query The query object.
  *
  * @return void
  */
 public function action_pre_get_posts($query)
 {
     /**
      * We only want our code to run in the main WP query
      * AND if an orderby query variable is designated.
      */
     if ($query->is_main_query() && ($orderby = $query->get('orderby'))) {
         switch ($orderby) {
             case 'location':
                 $query->set('meta_key', '_conference_location');
                 break;
             case 'conference':
                 $query->set('meta_key', '_conference_name');
                 break;
             case 'conference_date':
                 $query->set('meta_key', '_presentation_date');
                 break;
         }
         $query->set('orderby', 'meta_value');
     }
 }
开发者ID:ChrisWiegman,项目名称:chriswiegman-plugin,代码行数:32,代码来源:class-speaking.php

示例15: queasy_question_filter_query_by_group

/**
 * filter on a particular group
 *
 * @param WP_Query $query
 * @param int $id
 * @return WP_Query
 */
function queasy_question_filter_query_by_group(WP_Query $query, $id)
{
    $meta = array();
    if (!empty($id)) {
        $meta[] = array(array('key' => 'queasy_question_group', 'value' => $id, 'compare' => '='));
    }
    if (count($meta)) {
        $meta['relation'] = 'AND';
        $query->set('meta_query', $meta);
    }
    return $query;
}
开发者ID:AdFabConnect,项目名称:wordpress-queasy,代码行数:19,代码来源:queasy_question.php


注:本文中的WP_Query::set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。