[英]I am having trouble excluding a custom taxonomy from an archive page for a custom post type in wordpress
[英]Having trouble with wordpress custom taxonomy archive
我在使用自定義分類模板時遇到了一些麻煩。 我繼承了一個由其他人開發的網站,他們使用“類型”插件添加一些自定義分類法。
在example-domain.com/people/harrison-ford中有一個僅顯示其中具有特定分類術語的帖子的存檔模板
此代碼引入了未選擇分類法的帖子。
<?php
$year = get_post_meta($post->ID, 'year', true);
$post_type = 'post';
$tax = 'people';
$tax_terms = get_terms( $tax );
if ($tax_terms) {
$args = array(
'post_type' => $post_type,
'people' => 'harrison-ford',
"$tax" => $tax_term->slug,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1,
'orderby' => 'date',
'order' => DESC
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) : ?>
<h2 class="wwNews"><?php echo $tax_term->name; ?> News</h2>
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<-- display stuff -->
<?php endwhile; // end of loop ?>
<?php endif; // if have_posts()
wp_reset_query();
}
?>
您在這里期待什么? "$tax"
將是'people' =>
,這將覆蓋'harrison-ford'
為$tax_term->slug
的值。
'people' => 'harrison-ford',
"$tax" => $tax_term->slug,
此外,我不知道有任何名為people
自定義參數,我很確定您需要tax_query
:
'tax_query' => array(
'taxonomy' => 'people',
'terms' => array('harrison-ford', $tax_term->slug)
)
這將給你匹配所有的人的結果, harrison-ford
和價值$tax_term->slug
的分類法中people
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.