本文整理汇总了PHP中WP_Query::is_main_query方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Query::is_main_query方法的具体用法?PHP WP_Query::is_main_query怎么用?PHP WP_Query::is_main_query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Query
的用法示例。
在下文中一共展示了WP_Query::is_main_query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wpml_home_url_parse_query
/**
* @param WP_Query $q
*
* @return mixed
*/
function wpml_home_url_parse_query($q)
{
if (!$q->is_main_query()) {
return $q;
}
global $sitepress_settings;
$site_url = get_site_url();
$parts = parse_url($site_url);
if (!isset($parts['path'])) {
$parts['path'] = '';
}
if (!WPML_Root_Page::is_current_request_root()) {
return $q;
} else {
remove_action('parse_query', 'wpml_home_url_parse_query');
$request_array = explode('/', $_SERVER["REQUEST_URI"]);
$sanitized_query = array_pop($request_array);
$potential_pagination_parameter = array_pop($request_array);
if (is_numeric($potential_pagination_parameter)) {
if ($sanitized_query) {
$sanitized_query .= '&';
}
$sanitized_query .= 'page=' . $potential_pagination_parameter;
}
$sanitized_query = str_replace('?', '', $sanitized_query);
$q->parse_query($sanitized_query);
add_action('parse_query', 'wpml_home_url_parse_query');
$q->query_vars['page_id'] = $sitepress_settings["urls"]["root_page"];
$q->query['page_id'] = $sitepress_settings["urls"]["root_page"];
$q->is_page = 1;
$q->queried_object = new WP_Post(get_post($sitepress_settings["urls"]["root_page"]));
$q->queried_object_id = $sitepress_settings["urls"]["root_page"];
$q->query_vars['error'] = "";
$q->is_404 = false;
$q->query['error'] = null;
}
return $q;
}
示例2: 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);
}
}
示例3: 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);
}
}
示例4: 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');
}
}
示例5: maybe_display_post
/**
* Conditionally add a hook on posts_results if this is the main query, a preview, and singular.
*
* @since 4.4.0
*
* @param WP_Query $query
*
* @return WP_Query
*/
public function maybe_display_post($query)
{
if ($query->is_main_query() && $query->is_preview() && $query->is_singular()) {
add_filter('posts_results', array($this, 'set_post_to_publish'), 10, 2);
}
return $query;
}
示例6: 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);
}
}
}
示例7: action_pre_get_posts
/**
* @param WP_Query $wp_query
*
* @return WP_Query
*/
public function action_pre_get_posts(WP_Query $wp_query)
{
if (is_admin()) {
return;
}
if (!empty($wp_query->query_vars['suppress_filters'])) {
return;
}
# Further reading:
# https://core.trac.wordpress.org/ticket/14589
# https://core.trac.wordpress.org/ticket/19471
if (!$wp_query->is_main_query()) {
return;
}
if ($wp_query->is_tag()) {
$taxomony = 'post_tag';
} else {
if ($wp_query->is_category()) {
$taxomony = 'category';
} else {
return;
}
}
$post_type = $wp_query->get('post_type');
if (empty($post_type)) {
$post_type = $this->post_type_support_taxomony($taxomony);
}
$wp_query->set('post_type', $post_type);
return $wp_query;
}
示例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;
}
示例9: 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;
}
示例10: first_post_full_length_enable
/**
* @param WP_Query $query
*/
function first_post_full_length_enable($query)
{
if (!is_admin() && $query->is_main_query() && !$query->is_feed()) {
// set is_feed to true, so that the post content will be used in full length
$query->is_feed = true;
// add a filter that sets is_feed to false again, as soon as the content from the first post was set
add_filter('the_post', 'first_post_full_length_disable');
}
}
示例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);
}
}
}
示例12: filter__the_posts
/**
* This filter is needed to display correctly the posts with the '--- MORE ---' separator
* in archives.
* Without it, the post content is truncated at the beginning of <!--more-->, thus keeping
* only the first language.
* *
* 'the_posts' filter is used by @see get_posts(), which is commonly used in all sorts of places,
* including, for instance, @see wp_get_associated_nav_menu_items while deleting a post.
* So, to minimize potential side effects, we limit the scope to main queries, or
* when the 'wpglobus_force_filter__the_posts' is set
* (@see WPGlobus_QA::_test_get_posts for example).
*
* @param array $posts
* @param WP_Query $query
*
* @return array
* @since 1.0.14
*/
public static function filter__the_posts($posts, &$query)
{
if ($query->is_main_query() || $query->get('wpglobus_force_filter__the_posts')) {
foreach ($posts as $post) {
WPGlobus_Core::translate_wp_post($post, WPGlobus::Config()->language, WPGlobus::RETURN_IN_DEFAULT_LANGUAGE);
}
}
return $posts;
}
示例13:
function charitable_add_user_dashboard_menu(WP_Query $query)
{
if (!$query->is_main_query()) {
return;
}
if (!charitable_get_user_dashboard()->in_nav()) {
return;
}
charitable_get_user_dashboard()->nav(array('container_class' => 'user-dashboard-menu'));
}
示例14: handle
public function handle(\WP_Query $query)
{
if (is_admin() || !$query->is_main_query()) {
return;
}
if ($query->is_home()) {
//$query->set('posts_per_page', '10');
}
//$query->set( 'posts_per_page', '2' );
}
示例15: gp_abort_main_wp_query
/**
* Prevents executing WP_Query's default queries on GlotPress requests.
*
* The following code effectively avoid running the main WP_Query queries by setting values before
* they are run.
*
* @link http://wordpress.stackexchange.com/a/145386/40969 Original source.
*
* @since 1.0.0
*
* @param array $request The complete SQL query.
* @param WP_Query $wp_query The WP_Query instance (passed by reference).
* @return string|false False if GlotPress request, SQL query if not.
*/
function gp_abort_main_wp_query($sql, WP_Query $wp_query)
{
if ($wp_query->is_main_query()) {
// Prevent SELECT FOUND_ROWS() query.
$wp_query->query_vars['no_found_rows'] = true;
// Prevent post term and meta cache update queries.
$wp_query->query_vars['cache_results'] = false;
return false;
}
return $sql;
}