2013-10-04 93 views
0

如何獲得所有自定義帖子(post_type = family_guy)及其多維數組中的所有自定義帖子(post_type = family_guy)?返回特定多維數組中的所有wordpress自定義帖子

這正是我怎麼會喜歡我的陣列看起來像:

$array = array("1" => Array(
          "Peter1", 
          "Lois1", 
          "Megan1" 
        ), 
      "2" => Array(
          "Peter2", 
          "Lois2", 
          "Megan2" 
        ), 
      "3" => Array(
          "Peter3", 
          "Lois3", 
          "Megan3" 
        ), 
     "4" => Array(
          "Peter4", 
          "Lois4", 
          "Megan4" 
        ) 
     ); 

在這個數組,鍵將被自定義信息的ID,和值將是自定義後的所有標籤。

在此先感謝。

+0

你能否向我們提供你已經寫好的代碼在function.php.i中註冊這個代碼,我想檢查你已經應用了哪種分類法,或者你已經申請或者不先申請。 –

+0

我已經實現了帶有自定義帖子類型的自定義帖子。我能夠搜索這個自定義類型,但我無法獲得包含ID和標籤的數組。 –

+0

爲了得到這個,你必須首先註冊一個文本並在後期類型註冊參數中提及,然後你可以得到所有這些東西。我問像這樣的:的$ args =陣列( \t \t '標籤'=> $標籤, \t \t '公共'=>真實, \t \t 'publicly_queryable'=>真實, \t \t 'show_ui'= >真, \t \t 'query_var'=>真, \t \t '改寫'=>真, \t \t 'capability_type'=> '後', \t \t '分層'=>假, \t \t'menu_position'=> null \t); \t \t //註冊我們剛剛設置的以上內容 \t register_post_type('post-type-name',$ args); –

回答

1

東西沿着這些線路應該幫助,在functions.php的

function cpt_tag_list() { 
    $types = get_post_types(array(
     '_builtin' => false // This returns only custom post types 
     'public' => true  // Not necessarily right, but consider this, you may need to filter out CPTs made by plugins. 
    )); 

    $op = array(); 
    $i = 0; 

    foreach ($types as $cpt) { 
     $i++; 

     $posts_in_cpt = new WP_Query("posts_per_page=-1&post_type={$cpt}"); 

     $tags_used = array(); 

     foreach ($posts_in_cpt as $post) { 
      $tags_used[] = get_tags($post->ID); 
     } 

     $op[(string) $i] = array_unique($tags_used); 
    } 

return $op 
} 

,然後通過調用cpt_tag_list()調用在您的網站;如果我在這方面犯了什麼錯誤,我沒有機會去測試它,但希望它的要點在你身上。

+0

我明白了邏輯。謝謝。 –

相關問題