2016-11-07 2 views
1

통계를 수집 중이며 거기에 모든 페이지, 게시물, 분류 카테고리를 표시하고 싶습니다. 실제로 모두가 어떤 포스트 유형을 가지고 있지만 그들과 함께 분류 범주를 표시 할 수 없습니다 때문에 포스트 유형과 페이지를 표시 할 수게시물, 카테고리, 페이지가 함께 표시됩니다 - wordpress

:

<?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

관련 문제