我已经尝试了三天来解决这个问题,甚至在这个网站上使用了解决方案。我还是不能让它工作。
我有一个wordpress循环,它使用过滤器来按帖子类型显示帖子。现在,帖子类型被称为“案例研究”,因此类型案例研究中的所有帖子都会显示出来。
但是我需要在这个循环中隐藏一个特定的分类法术语。分类被称为“行业”,术语是“医疗保健”。我尝试了所有的组合,但仍然不能得到这个。我需要这个非常紧急的东西。任何能帮忙的人都会救我的命。
下面是查询和循环
<?php
// The Query
$the_query = new WP_Query( 'post_type=case-studies&posts_per_page=-1' );
// The Loop
while ( $the_query->have_posts() ) :
$the_query->the_post();
?>发布于 2013-10-21 17:43:35
$args = array(
'post_type' => 'case-studies',
'tax_query' => array(
array(
'taxonomy' => 'sectors',
'field' => 'slug',
'terms' => array('comercial', 'personal', 'etc') //excluding the term you dont want.
)
)
);
$query = new WP_Query( $args );我不想尝试,但你可以只做一个查询调用你想要的术语,你可以以前填充terms数组,列出分类上的所有术语,并排除你想要的,我认为这有点老生常谈它应该是另一种直接的方法,但尝试一下,因为这是一个生死存亡的案例)。
来源:http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
发布于 2013-10-21 18:08:11
试试这个:
<?php
$type = 'cpreviews';
$args=array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>发布于 2013-10-21 21:36:58
好的,然后试试这个,它会自动提取你的词条,并排除你不想要的词条,我没有检查它是否工作,但这是逻辑,请检查sintax错误。
$terms = get_terms("sectors");
$count = count($terms);
$termsAr = array();
if ($count > 0 ){
foreach ( $terms as $term ) {
if($term->name !== "healthcare"){//Here we exclude the term or terms we dont want to show
array_push($termsAr, $term->name);
}
}
}
$terms = get_terms("types");
$count = count($terms);
$termsAr2 = array();
if ($count > 0 ){
foreach ( $terms as $term ) {
if($term->name !== "healthcare"){//Here we exclude the term or terms we dont want to show
array_push($termsAr2, $term->name);
}
}
}
$args = array(
'post_type' => 'case-studies',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'sectors',
'field' => 'slug',
'terms' => $termsAr //excluding the term you dont want.
),
array(
'taxonomy' => 'types',
'field' => 'slug',
'terms' => $termsAr2 //excluding the term you dont want.
)
)
);
$query = new WP_Query( $args );https://stackoverflow.com/questions/19490762
复制相似问题