duanji1902 2014-12-30 19:17
浏览 37

如何从自定义查询短代码中排除类别?

I am using isotopes on one of my template. I dynamic it using custom query shortcode.

the codes are given below.

function saints_shortcode($atts){
        extract( shortcode_atts( array(
                'category' => ''
        ), $atts, 'saints' ) );

    $q = new WP_Query(
        array('posts_per_page' => '-1', 'post_type' => 'saints_list', 'order' => 'ASC')
        );             

//saint taxanomy query
        $args = array(
                'post_type' => 'saints_list',
                'order' => 'ASC',
                'paged' => $paged,
                'posts_per_page' => $data['saint_items'],
        );

        $saint = new WP_Query($args);
        if(is_array($saint->posts) && !empty($saint->posts)) {
                foreach($saint->posts as $gallery_post) {
                        $post_taxs = wp_get_post_terms($gallery_post->ID, 'saint_category', array("fields" => "all"));
                        if(is_array($post_taxs) && !empty($post_taxs)) {
                                foreach($post_taxs as $post_tax) {
                                        $saint_taxs[$post_tax->slug] = $post_tax->name;
                                }
                        }
                }
        } 
        if(is_array($saint_taxs) && !empty($saint_taxs) && get_post_meta($post->ID, 'pyre_saint_filters', true) != 'no'):
?>
                <div class="remove-ext">
                    <section id="options">
                        <div class="option-combo">
                            <ul id="filter" class="option-set" data-option-key="filter">
                                <li><a href="#show-all" data-option-value="*" class="selected">show all</a></li>
                                <?php foreach($saint_taxs as $saint_tax_slug => $saint_tax_name): ?>
                                <li><a href="#" data-option-value=".<?php echo $saint_tax_slug; ?>"><?php echo $saint_tax_name; ?></a></li>
                                 <?php endforeach; ?>
                            </ul>
                        </div>
                    </section>  
                <?php endif; ?>

<?php

        $list = '              
        <div class="masonary-product">';
        while($q->have_posts()) : $q->the_post();
                $idd = get_the_ID();
                $saint_subtitle = get_post_meta($idd, 'saint_subtitle', true);
                $filterr = get_post_meta($idd, 'filterr', true);
                $small_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'saint-image_small' );

                //Get Taxonomy class

                $item_classes = '';
                $item_cats = get_the_terms($post->ID, 'saint_category');
                if($item_cats):
                foreach($item_cats as $item_cat) {
                        $item_classes .= $item_cat->slug . ' ';
                }
                endif;


                $list .= '
                <div class="col-md-3 '.$item_classes.'">
                    <div class="member">
                        <div class="team">
                            <div class="team-img">
                                <img src="'.$small_image_url[0].'" alt="" />
                            </div>
                            <div class="member-detail">
                                <h3><a href="'.get_permalink().'" title="">'.get_the_title().'</a></h3>
                                <p>'.substr(get_the_excerpt(), 0,100).'</p>
                            </div>
                        </div>
                    </div><!-- MEMBER -->
                </div>

                ';        
        endwhile;
        $list.= '</div></div>';
        wp_reset_query();
        return $list;
}
add_shortcode('saints', 'saints_shortcode');

Its working very well.

now i want to exclude a category like 'Executive Member'. i tried to exclude but its not working. How can i exclude any category that I want.

Anyone can help me.

TIA

  • 写回答

1条回答 默认 最新

  • dongrong7883 2014-12-31 11:21
    关注

    Try with this code.

     $q = new WP_Query(array('posts_per_page' => '-1', 'post_type' => 'saints_list', 'order' => 'ASC','category__not_in' =>'Executive Member'));  
    
    $args = array(
                'post_type' => 'saints_list',
                'order' => 'ASC',
                'paged' => $paged,
                'posts_per_page' => $data['saint_items'],
                'category__not_in' =>'Executive Member',
    
        );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么