2013-05-30 4 views
0

루프에 분류법 인수를 추가 할 때까지 정상적으로 작동하고 게시물을 출력하는 기본 WordPress 루프가 있습니다. 루프에 추가하면 아무 것도 출력하지 않지만 PHP 오류는 발생하지 않습니다. 루프가 아래에 있습니다.taxonomy WordPress 쿼리가 작동하지 않습니다.

<?php 
    $newsLoop = new WP_Query(array('post_type' => 'news&events', 'taxonomy' => 'postcategory', 'term' => 'featured', 'posts_per_page' => 3, 'orderby' => 'post_date', 'order' => 'ASC')); 
    while ($newsLoop->have_posts()) : $newsLoop->the_post(); 
?> 

<div class="newsEvent"> 

<h2><?php the_title(); ?></h2> 

<?php the_excerpt(); ?> 

<p style="text-align:center;"><a href="<?php the_permalink(); ?>">Read More</a></p> 

</div> 

<?php endwhile; wp_reset_postdata(); ?> 

게시물 유형 인수를 모두 제거하고 택 소노 미를 쿼리하는 중, 행운이 없었습니다. 여기에 누락되었거나 올바르게 작동하지 않는 것이 있습니까? 나는 몇 주 전에 여기에 비슷한 일에 종사 한 http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

답변

0

당신은 tax_query 매개 변수를 사용해야합니다 Functions.php : (분류법을 등록하기 위해).

$args = array(
     'hierarchical'  => true, 
     'labels'   => $labels, 
     'show_ui'   => true, 
     'show_admin_column' => true, 
     'query_var'   => true, 
     'rewrite'   => array('slug' => 'news-category'), 
    ); 
register_taxonomy('news-tax', array('news&events'), $args); 

이제 쿼리

<?php $args = array('news-tax' => 'postcategory', 'post_type' => 'news&events', 'orderby' => 'post_date','order' => 'ASC', 'posts_per_page' => -1); 
        $loop = new WP_Query($args); 
        while ($loop->have_posts()) : $loop->the_post();?> 

날이 작동하는지 알아 보자! 또한 '뉴스 & 이벤트'를 분류없이 성공적으로 쿼리 할 수 ​​있었습니까? & 앰프가 문제의 원인 일 수 있습니까? 어느쪽으로 든, 나는 많은 방법을 시도하고 위는 저를 위해 이음새가 없 완벽하게 작동했다.

+0

나는 이것을 실제로 시도해 보았습니다. 같은 결과. 또한 택 소노 미를 통해 쿼리 할 때도 필요하지 않습니다. 보다 복잡한 분류 쿼리의 경우 선택 사항입니다. – AndyWarren

+0

값을 다시 확인 했습니까? 'post_type => array ('news', 'events')'를 쿼리하려고 했습니까? – diggy

+0

모든 값을 여러 번 확인했습니다. 게시물 유형은 News & Events 호출이므로 쿼리가 정확합니다. 이는 매우 이상한 행동이며, 어떤 종류의 분류 론적 주장을 소개하기 전까지는 쿼리가 훌륭하게 작동합니다. – AndyWarren

1

나는 당신을 위해이 작업은 다음과 같습니다 :

$args = array(
    'post_type' => 'news&events', 
    'tax_query' => array(
     array(
      'taxonomy' => 'postcategory', 
      'field' => 'slug', 
      'terms' => 'featured' 
     ) 
    ), 
    'posts_per_page' => 3, 
    'orderby' => 'post_date', 
    'order' => 'ASC' 
); 
$newsLoop = new WP_Query($args); 

이 문서를 확인하십시오

관련 문제