2012-01-03 41 views
2

我想要列出屬於某些帖子ID的給定類別的帖子。WordPress的:獲取特定類別的帖子

示例:從categoryA或類別b帖子其具有ID 1,2,3,4,5

+1

那麼,什麼問題? – 2012-01-03 11:45:29

+0

我如何搜索使用這兩個類別和帖子ID – 2012-01-04 03:51:14

回答

0

get_posts使用與所述類別和包括參數。

+0

,但你不能同時使用兩個類別和post ID與get_posts – 2012-01-04 03:50:35

+1

是的,是的,你可以。 – addedlovely 2012-01-04 11:43:08

+0

你可以解釋如何在一個查詢中搜索兩個 – 2012-01-06 03:45:18

2

使用get_postspost__incat可能會滿足您的需求:

// Create your query argument array 
$args = array(
     'cat' => '1,2', // Where 1 and 2 are the category ids of Category A and Category B that you want posts containing either of. 
     'post__in' => array (1,2,3,4,5) // Where 1-5 are post ids 
    ); 

// Retrieve posts 
$post_list = get_posts($args); 

$post_list將檢索到的帖子陣列基於傳遞給get_posts查詢參數。

您可以在get_postshere以及更多關於有效查詢參數的信息here上獲得更多信息。

+0

,但你不能同時使用這兩個類別和post ID與get_posts – 2012-01-04 03:50:19

+0

我添加了一些代碼,顯示如何將類別slugs或名稱轉換爲id。 – Chaser324 2012-01-04 10:51:55

+0

此外,你真的應該重寫這個問題,以更清楚地說明你的實際問題是什麼。 – Chaser324 2012-01-04 11:50:15

相關問題