按术语将帖子从循环中排除

时间:2019-06-04 作者:george

下面是循环的外观?我需要排除一些带有自定义术语的帖子,我如何管理它

<?php
    global $post, $PIXAD_Autos;
    $Settings = new PIXAD_Settings();
    $settings = $Settings->getSettings( \'WP_OPTIONS\', \'_pixad_autos_settings\', true );

    $validate = $Settings->getSettings( \'WP_OPTIONS\', \'_pixad_autos_validation\', true ); // Get validation settings

    $showInSidebar = pixad::getsideviewfields($validate);
    $validate = pixad::validation( $validate ); // Fix undefined index notice

    $auto_translate = unserialize( get_option( \'_pixad_auto_translate\' ) );


    ?>

    <div class="row">
            <?php while ( have_posts() ) : the_post(); ?>
                <?php 
                $comment_args = array( \'status\' => \'approve\', \'post_id\' => $post->ID, );
                $comments = get_comments($comment_args);
                $post_rating = [];
                foreach($comments as $comment){
                    $post_rating[] = floatval( get_comment_meta( $comment->comment_ID, \'rating\', true ) );
                }
                ?>

            <div class="col-md-4">
                               <div class="slider-grid__inner slider-grid__inner_mod-b">

                                    <div class="card__img">
                       <?php if( has_post_thumbnail() ): ?>
                         <a href="<?php the_permalink(); ?>">
                            <?php the_post_thumbnail(\'autozone_latest_item\', array(\'class\' => \'img-responsive\')); ?>
                        </a>


                    <?php else: ?>
                        <img class="no-image" src="<?php echo PIXAD_AUTO_URI .\'assets/img/no_image.jpg\'; ?>" alt="no-image">
                    <?php endif; ?>


                    <?php if( get_post_meta(get_the_ID(), \'pixad_auto_featured_text\', true) ): ?>
                        <span class="card__wrap-label"><span class="card__label"><?php echo  get_post_meta( get_the_ID(), \'pixad_auto_featured_text\', true ); ?></span></span>
                    <?php endif; ?>


                    <?php if( $validate[\'auto-price_show\'] && $PIXAD_Autos->get_meta(\'_auto_price\') ): ?>
                   <span class="slider-grid__price_wrap"><span class="slider-grid__price"><span><?php echo wp_kses_post($PIXAD_Autos->get_price()); ?></span></span></span> 
                    <?php endif; ?>
                    <?php do_action( \'autozone_autos_single_auto_img\', $post ); ?>
                </div>
                         <div class="tmpl-gray-footer">
                            <span class="tmpl-slider-grid__name"><?php echo wp_kses_post(get_the_title())?></span>
                        <?php if(!empty($post_rating)):?>
                            <div class="star-rating"><span style="width:<?php echo  esc_html( array_sum($post_rating)/count($post_rating) * 20 );?>%"></span></div>
                        <?php endif;?>      

                        <ul class="tmpl-slider-grid__info list-unstyled">

                                 <?php foreach ($showInSidebar as $id => $sideAttribute):?>
                                      <?php   $id=\'_\'.$id; 
                                     $id = str_replace(\'-\', \'_\', $id); 
                                      ?>
                                     <?php  if( $PIXAD_Autos->get_meta($id) ): ?>
                                    <li><i class="<?php echo esc_html($sideAttribute[\'icon\'])?>"></i>
                                        <?php
                                        $val_attr =  $PIXAD_Autos->get_meta($id);
                                        if(!empty($auto_translate[$val_attr])  ){
                                          echo esc_html($auto_translate[$val_attr]);
                                        }else{
                                          echo esc_html($PIXAD_Autos->get_meta($id));
                                        }
                                          ?>
                                    </li>
                                     <?php endif; ?>

                                 <?php endforeach;?>
                             </ul>
                            </div> 

                         </div>  
                </div>
            <?php endwhile; ?>

    </div>

2 个回复
SO网友:brothman01

您是否在问如何排除包含特定文本的帖子?(国防部请将此移至评论,我没有声誉)

SO网友:george

答案很简单,很抱歉打扰你)

if( has_term( \'taxonomy slug\', \'taxonomy\' ) ) { 
continue;
}

相关推荐

Loop stopped working

我有一个巨大的问题,我打破了我的had,试图找到正确的解决方案。我有以下循环代码。此循环位于我的页面产品中。php文件:<?php $terms = get_the_terms( get_the_ID(), \'colour\' ); if ( $terms && ! is_wp_error( $terms ) ) : ?> <section class=\"colour__chart\"> <