Excluded Custom Taxonomy Term Posts Displaying in loop

I created a custom post type called "careers" with a custom post type taxonomy called "careers_categories

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
Add a comment  | 

1 Answer 1

Reset to default 0

Try below methods:

  1. Try by adding term ID in array like this 'exclude'=> '60' in array

  2. If 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 );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742372610a4431556.html

相关推荐

  • Excluded Custom Taxonomy Term Posts Displaying in loop

    I created a custom post type called "careers" with a custom post type taxonomy called "careers_categories

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信