2016-06-07 43 views
0

我有一個帖子ID的列表,我想循環的帖子,我已經嘗試使用WP_QUERY與post_in,但這並不保留該命令id的列在$ sorted數組中。WordPress的 - 循環了ID號碼數組中發現的帖子

什麼是最簡單的方式循環id的數組作爲職位,但覆蓋美國排序的排序的訂單的自然後序?

$args = array (
    'post__in' => $sorted, // array of id's that I want in order 
    'posts_per_page' => -1, // so that it shows everything in the array 
    'ignore_sticky_posts' => 1 // so that stickys dont affect order 
); 



$query = new WP_Query($args); 

// The Loop 
if ($query->have_posts()) { 
    echo '<ul>'; 
    while ($query->have_posts()) { 
     $query->the_post(); 
     echo '<li>n' . get_the_title() . ' - '. get_the_ID() .'</li>'; 
    } 
    echo '</ul>'; 
} else { 
    _e('Sorry, no posts matched your criteria.'); 
} 

wp_reset_postdata(); 
+0

你的意思是說,你想通過郵寄ID右門柱訂單? –

+0

@ sameer-sheikh不列出數組$ sort中的ID的順序。覆蓋自然的後序。 – martyish

回答

0

你可以用 '排序依據'=> 'post__in'

<?php 
$postsArgs = array(
    "post_type" => "post", 
    "orderby" => "post__in", 
    "order" => "ASC", 
    "posts_per_page" => "-1", 
    "post__in" => array(1,8,6) 
); 
$posts = new WP_Query($postsArgs); 
?> 
+0

不要按$的排列順序排列ID(問題在於它按照帖子ID的順序排列,即使按ID排序時也是如此,我將如何忽略自然排序和顯示他們的順序$排序aray) – martyish

+1

好吧,知道了,更新了我的答案。 使用 'orderby'=>'post__in' 改爲 –