【发布时间】:2016-01-14 20:31:45
【问题描述】:
我有以下查询来收集粘性帖子。这在我实际上有粘性帖子时有效,但是当我没有粘性帖子时,它只会查询 10 个(无粘性)帖子。我如何调整查询以仅收集粘性帖子,如果没有找到,则什么也不做。谢谢
/* Get all sticky posts */
$sticky = get_option( 'sticky_posts' );
/* Sort the stickies with the newest ones at the top */
rsort( $sticky );
/* Get the 5 newest stickies (change 5 for a different number) */
$sticky = array_slice( $sticky, 0, 5 );
/* Query sticky posts */
$the_query2 = new WP_Query( array( 'ignore_sticky_posts' => 'false', 'post__in' => $sticky, 'post_type' => 'ad_listing' ) );
echo $the_query2->post_count;
【问题讨论】:
-
这里请注意,仅查询置顶帖时,将
ignore_sticky_posts设置为true