admin管理员组文章数量:1334917
I created a custom post type called "careers" with a custom post type taxonomy called "careers_categories". Within this taxonomy I have a term called "featured". My intent is to exclude all post within the loop that contain the term "featured" with a term ID of 60, the terms will be displayed in the archive-careers.php and I am using ISOTOPE PLUGIN to create a filter for the accompanying posts.I would also like to have the "featured" post display in a hero at the top of the page. The terms are displayed as links and the filtering works with the accompanying post in the query below. The "featured" term is not displaying as a link but the post associated with the term is still displaying. It is important to note that the post that contains the term "featured" can also have the another term like "graphic_design" and I would like them to be displayed under the secondary term. please see my code below:
<?php get_header(); ?>
<div class="container">
<div class="row">
<div class="fl-content col-lg-12">
<?php $terms =
get_terms( array(
'taxonomy' => 'careers_categories',
'hide_empty' => true,
'exclude'=> '60',
));?>
<div class="hero">
<?php if( has_term('', 'featured') ){
the_title();
}?>
</div>
<?php if( $terms ) {
?>
<ul id="my-category" class="filter clearfix">
<li><a href="#" class="active" data-filter="*"><span>All</span></a></li>
<?php foreach( $terms as $term ){
echo "<li><a href='#' data-filter='.$term->slug'><span>$term->name</span></a></li>";
} ?>
</ul>
<?php }
if( have_posts() ) { ?>
<div id="cpt-wrap" class="clearfix filterable-cpt grid" data-isotope='{ "itemSelector": ".grid-item", "layoutMode": "fitRows" }'>
<div class="cpt-content">
<?php while( have_posts() ): the_post(); ?>
<?php $terms = get_the_terms( get_the_ID(), 'careers_categories' ); ?>
<?php
global $post; ?>
<article class="grid-item cpt-item <?php if( $terms ) foreach ( $terms as $term ) { echo $term->slug.' '; }; ?>">
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
<?php
if ( has_post_thumbnail($post->ID) ) {
echo the_post_thumbnail();
} ?>
<h3><?php the_title(); ?></h3>
</a>
</article>
<?php endwhile; ?>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<?php get_footer();
I created a custom post type called "careers" with a custom post type taxonomy called "careers_categories". Within this taxonomy I have a term called "featured". My intent is to exclude all post within the loop that contain the term "featured" with a term ID of 60, the terms will be displayed in the archive-careers.php and I am using ISOTOPE PLUGIN to create a filter for the accompanying posts.I would also like to have the "featured" post display in a hero at the top of the page. The terms are displayed as links and the filtering works with the accompanying post in the query below. The "featured" term is not displaying as a link but the post associated with the term is still displaying. It is important to note that the post that contains the term "featured" can also have the another term like "graphic_design" and I would like them to be displayed under the secondary term. please see my code below:
<?php get_header(); ?>
<div class="container">
<div class="row">
<div class="fl-content col-lg-12">
<?php $terms =
get_terms( array(
'taxonomy' => 'careers_categories',
'hide_empty' => true,
'exclude'=> '60',
));?>
<div class="hero">
<?php if( has_term('', 'featured') ){
the_title();
}?>
</div>
<?php if( $terms ) {
?>
<ul id="my-category" class="filter clearfix">
<li><a href="#" class="active" data-filter="*"><span>All</span></a></li>
<?php foreach( $terms as $term ){
echo "<li><a href='#' data-filter='.$term->slug'><span>$term->name</span></a></li>";
} ?>
</ul>
<?php }
if( have_posts() ) { ?>
<div id="cpt-wrap" class="clearfix filterable-cpt grid" data-isotope='{ "itemSelector": ".grid-item", "layoutMode": "fitRows" }'>
<div class="cpt-content">
<?php while( have_posts() ): the_post(); ?>
<?php $terms = get_the_terms( get_the_ID(), 'careers_categories' ); ?>
<?php
global $post; ?>
<article class="grid-item cpt-item <?php if( $terms ) foreach ( $terms as $term ) { echo $term->slug.' '; }; ?>">
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
<?php
if ( has_post_thumbnail($post->ID) ) {
echo the_post_thumbnail();
} ?>
<h3><?php the_title(); ?></h3>
</a>
</article>
<?php endwhile; ?>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<?php get_footer();
Share
Improve this question
asked Jun 4, 2020 at 19:50
theartisttheartist
135 bronze badges
1 Answer
Reset to default 0Try below methods:
Try by adding term ID in array like this
'exclude'=> '60'
in arrayIf this is not working you can try with below
WP_Query
loop:
$args = array( 'post_type' => 'careers', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'careers_categories', 'field' => 'term_id', 'terms' => array( 60), 'operator' => 'NOT IN', ), ), ); $query = new WP_Query( $args );
本文标签: Excluded Custom Taxonomy Term Posts Displaying in loop
版权声明:本文标题:Excluded Custom Taxonomy Term Posts Displaying in loop 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742372609a2462529.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论