2009-07-29 16 views
1

我已經包含在$ postarray後ID數組。我想在Wordpress中打印與這些ID相對應的帖子。 我使用的代碼如下:我怎麼能有WordPress的帖子打印其ID出現在一個陣列?

query_posts(array('post__in' => $postarray)); 
if (have_posts()) : 
    while (have_posts()) : the_post(); 
     the_title(); 
     the_excerpt(); 
    endwhile; 
endif; 

儘管如此,循環打印最近發表的文章,而不是包含在數組中的職位。我如何讓wordpress使用我在數組中提供的帖子ID並按順序打印這些帖子?

+0

我繼續鍵入答案,但應該工作。你可能想嘗試製作一個新的WP Query類。 – 2009-07-29 16:06:41

+0

嘗試新WP_Query(); - 沒有運氣。 – 2009-07-29 16:52:18

回答

0

您可能需要打出來的標準WP循環這個的......

嘗試使用的get_post()函數,它接受一個帖子的ID,並返回包含的細節對象該文章採用通常的OBJECT或Associate或Numeric Array格式。

請參閱full-explanation of get_post()

你能想出一個自定義例程在陣列中解析每個項目。這裏有一個簡單的例子:

function get_posts_by_ids($postarray = null) { 
    if(is_array($postarray)) 
     foreach($postarray as $post) { 
      $post_details = get_post($post[0]); 

      // Title 
      echo $post_details->post_title; 
      //Body 
      echo $post_details->post_content ; 
     } 
} 

希望這有助於:)