[英]Query posts with specific Taxonomy first
到目前為止,我正在嘗試查詢wordpress中的帖子。 但是,我想在所有人面前(甚至在粘性前面)顯示帶有特定標簽“ info”的帖子。
我以為我可以將查詢合並到這樣的數組中:
$posts = array( 'post__in' => $sticky, 'order' => $order_posts, 'ignore_sticky_posts' => 1, 'paged' => $paged );
$infoposts = array('tag' => 'info', 'post__in' => $sticky);
query_posts ( array_merge( $infoposts, $posts ));
但是,這只會發布$ infoposts數組帖子。 如何同時獲得兩個信息以及帶有“ info”標簽的信息?
這個怎么做?
謝謝!
array_merge
將您的數組合並在一起,var_dump array_merge( $infoposts, $posts )
以了解我的意思。
AFAIK您需要執行2個單獨的查詢,一個查詢用於粘性帖子,另一個查詢用於其他帖子。
-編輯-
$sticky = get_posts($infoposts);
$rest = get_posts($posts);
$all = array_merge($sticky, $rest);
foreach ( $all as $post ) : setup_postdata( $post ); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach;
wp_reset_postdata(); // this is important ?>
</ul>
tldr:使用get_posts代替查詢帖子
http://codex.wordpress.org/Function_Reference/query_posts http://codex.wordpress.org/Template_Tags/get_posts
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.