2016-11-07 8 views
1

私は統計情報を収集しています。そこには、私が持っているすべてのページ、投稿、分類分類を表示したいと思います。実際に彼らはすべてのいくつかのポストタイプを持っていますが、彼らと一緒に分類カテゴリを表示することができないので、私はポストタイプとページを表示でき投稿、カテゴリ、ページを一緒に表示する - ワードプレス

<?php 
    $excluded_ids = array(1, 5); 
    $postArgs = array(
     'post_type' => array('page', 'products'), 
     'order' => 'ASC', 
     'orderby' => 'title', 
     'post__not_in' => $excluded_ids, 
     'posts_per_page'=> -1, 
     /*'taxonomy' => 'product-category'*/ 
    ); 
    $postList = get_posts($postArgs); 
?> 

すべて(記事、カテゴリ、ページを表示する方法はあります)複数のクエリではなく単一のクエリを使用しますか?何か案は?

答えて

0

get_postsメソッドは、post_type値として配列を受け入れません。投稿を照会するにはWP_Queryを使用してください。

$args = array(
    'post_type' => array('page', 'products' ) 
); 
$query = new WP_Query($args); 
0

私はあなたの応答を正しく

$argss = array(
'post_type' => array('page', 'products'), 
'order' => 'ASC', 
'orderby' => 'title', 
'tax_query' => array(
    array(
     'taxonomy' => 'your taxonomies', 
     'field' => 'slug', 
     'terms' => 'your term', 
    ), 
), 
); 

$the_queryy = new WP_Query($argss); 

if ($the_queryy->have_posts()) { 
while ($the_queryy->have_posts()) { 
    $the_queryy->the_post(); 
         // echo stuff 
} 
wp_reset_postdata(); 
} 
+0

感謝をunderstanded場合。しかし、それは動作していません。ページ、製品は表示されますが、カテゴリは表示されません。 @タウラス – aidadev

関連する問題