我有一个查询,其中显示了捐赠者的姓名以及献礼。它使用日期元查询显示。
$args = array(
\'post_type\' => \'donors\',
\'order_by\' => \'id\',
\'order\' => \'DESC\',
\'posts_per_page\' => -1,
\'date_query\' => array(
array(
\'after\' => $from,
\'before\' => $to
),
\'inclusive\' => true,
),
\'meta_query\' => array(
array(
\'key\' => \'type\',
\'value\' => \'donor\',
\'compare\' => \'=\'
)
)
);
我想让它以一种不受限制的方式显示,但出于某种原因,它只显示252个项目,而应该显示378个项目。我能做多少查询有没有限制?
EDIT
这是我自定义查询的完整代码
$colors = array(\'#00274E\', \'#a33038\', \'#6391B5\');
$separators = array();
$sepcount = 0;
$sepindex = 0;
$args = array(
\'post_type\' => \'arcf_donors\',
\'order_by\' => \'id\',
\'order\' => \'DESC\',
\'posts_per_page\' => -1,
\'is_paged\' => true,
\'paged\' => $paged,
\'meta_query\' => array(
array(
\'key\' => \'type\',
\'value\' => \'donor\',
\'compare\' => \'=\'
)
)
);
$subquery = new WP_Query($args);
$separators = array(
\'http://.s3.amazonaws.com/wp-content/uploads/445_4387134.jpg\',
\'http://.s3.amazonaws.com/wp-content/uploads/564_3765091.jpg\',
\'http://.s3.amazonaws.com/wp-content/uploads/829_4027101.jpg\',
\'http://.s3.amazonaws.com/wp-content/uploads/988_4172711.jpg\',
\'http://.s3.amazonaws.com/wp-content/uploads/987_4120232.jpg\',
\'http://.s3.amazonaws.com/wp-content/uploads/127_3764954.jpg\',
\'http://.s3.amazonaws.com/wp-content/uploads/440_4241356resized.jpg\',
\'http://.s3.amazonaws.com/wp-content/uploads/127_3764954.jpg\',
\'http://.s3.amazonaws.com/wp-content/uploads/311_2996427.jpg\',
\'http://.s3.amazonaws.com/wp-content/uploads/445_4387134.jpg\'
);
<?php if ( $subquery->have_posts() ):
while ( $subquery->have_posts() ): $subquery->the_post();
$color = $colors[mt_rand(0,2)]; $sepcount++; ?>
<?php if ($sepcount == 5): ?>
<?php $sepindex++; ?>
<?php if ($sepindex > 9) $sepindex = 0;?>
<div id="post-290" class="<?php print $sepindex; ?> post-size-1x1 project type-project status-publish format-link hentry post-single has_thumb about about experiments experiments portfolio portfolio services services team team post" data-post-size="1x1">
<div class="inner-image-placeholder" id="post-290-in" style="background-image: url(\'<?php echo $separators[$sepindex]; ?>\');">
<div class="image-link-inner"></div>
</div>
</div>
<?php $sepcount = 0; ?>
<?php else: ?>
<div id="post" class=" post-size-<?php the_field(\'brick_size\'); ?> project type-project status-publish format-standard hentry has_thumb portfolio portfolio post" data-post-size="<?php the_field(\'brick_size\'); ?>" style="background-color:<?php echo $color; ?>">
<div class="post-wrapper inner-image-placeholder">
<!-- Begin Title Section -->
<div class="image-link-inner">
<?php
echo \'<p class="donor">\';
echo the_title();
echo \'</p>\';
if ($show == \'dedication\'):
if (get_field(\'brick_message\') != \'\' || get_field(\'block_message\') != \'\'):
echo \'<div class="image-post-overlay" style="display: block;"><div class="image-post-overlay-in">\';
if (get_field(\'brick_size\') == \'1x1\'):
echo \'<p>\'. the_field(\'brick_message\') .\'</p>\';
else:
echo \'<p>\'. the_field(\'block_message\') .\'</p>\';
endif;
echo \'</div></div>\';
endif;
endif;
?>
</div>
<!-- Begin Dedication Section -->
<?php if (get_field(\'brick_message\') != \'\' || get_field(\'block_message\') != \'\'): ?>
<div class="image-post-overlay">
<div class="image-post-overlay-in">
<?php
if ($show == \'name\'):
if (get_field(\'brick_size\') == \'1x1\'):
echo \'<p>\'. the_field(\'brick_message\') .\'</p>\';
else:
echo \'<p>\'. the_field(\'block_message\') .\'</p>\';
endif;
else:
echo the_title();
endif;
?>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
最合适的回答,由SO网友:Pieter Goosen 整理而成
尝试添加
\'post_type\' => \'any\',
\'post_stauts\' => \'any\',
看看会发生什么。这应该检索具有任何职位状态的所有职位类型中的职位。如果它只检索了252篇文章,那么其他文章就不符合查询中的条件。
另一件重要的事情是,对于如此多的帖子,您可能会超过检索这些帖子的最大执行时间,但这将导致错误。
您还应该在wp config中将调试设置为true。php,并通过这种方式检查是否返回任何错误。退房Debugging Wordpress
EDIT
您的问题实际上很简单,是预期的行为。运行自定义查询时,如果不运行,则直接运行另一个自定义查询,甚至使用主查询,第一个查询将中断第二个查询
reset 自定义查询。
使用WP_Query
或get_posts
在运行另一个查询之前,先重置postdata。这是用wp_reset_postdata()
.
使用此函数可以在使用newWP_Query
. 它恢复$post
变量设置为主查询中的当前职位。
要解决您的问题,只需添加wp_reset_postdata();
就在最后一个之前endif;