2012-09-27 3 views
1

모든 게시물 유형의 태그별로 관련 게시물을 가져 오는 데 문제가 있습니다. 아래의 코드를 사용하고 있습니다 :'post_type'과 'tag__in'이 (가) 잘 작동하지 않습니다.

<?php 
    $tags = wp_get_post_tags($post->ID); 
    if ($tags) { 
    echo 'Related Posts'; 
    $first_tag = $tags[0]->term_id; 
    $args=array(
     'tag__in' => array($first_tag), 
     'post__not_in' => array($post->ID), 
     'showposts'=>5, 
     'caller_get_posts'=>1, 
     'post_type' => array('food','travel') 
    ); 
    $my_query = new WP_Query($args); 
    if($my_query->have_posts()) { 
     echo '<ul>'; 
     while ($my_query->have_posts()) : $my_query->the_post(); ?> 
     <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li> 
     <?php 
     endwhile; 
     echo '</ul>'; 
    } 
    } 
?> 

올바른 게시물을 반환하지는 않지만 대신 최신 게시물을 표시합니다. WP 문서에서 12 번 확인했는데 구문이 정확합니다.

버그 인 경우이 패치가있는 사람이 있습니까? 또는 SQL 쿼리 접근법을 공유 할 수있는 또 다른 옵션이 있습니다.

답변

0

모든 플러그인을 사용 중지합니다. add_action('pre_get_posts',...

에 대한 플러그인 파일을 찾으십시오.이 동작으로 때때로 $my_query->query_vars['post_type']이 "any"로 바뀝니다.

저에게 그것은 Sticky Custom Post Types 플러그인이었습니다.

관련 문제