我有一种具有多种分类类型的自定义帖子类型。这个问题仅集中在其中之一。我需要显示所有具有特色供应商的分类法的自定义帖子。目前,只有一个“特色”,但是将来可能还有更多,例如“亮点”或“赞助商”或单独的东西。但是,就目前而言,我只需要浏览所有“供应商”自定义帖子类型,然后在“特色供应商”分类法内找到带有“特色”检查的帖子。

我有一些帖子说,这是不可能的,但是它们要么是2.8或从今年的第一开始,而且我知道WordPress从那以后至少发布了一次更新。

提前致谢!!

有帮助吗?

解决方案

查询定制帖子类型按分类学术语


该样本将假设:

  • 自定义邮政类型已在分类法注册,分类法已注册为 'query_var' =>true'hierarchial' => true

  • “检查”术语将是 父母 任何新的都可以在以后添加为 孩子们。

编码:

 <?php query_posts( array( 'featured-vendors' => 'checked' ) ); ?>
    <?php if( is_tax() ) {
        global $wp_query;
        $term = $wp_query->get_queried_object();
        $title = $term->name;
    }  ?>

    <div class="my-custom-post">
    <h3><?php echo($title); ?></h3> //this will show the name of the post type
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

     <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 

    <div class="entry"> <h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>

        <?php the_excerpt(); ?> //shows the excerpt 

     </div><!--/end entry-->
</div><!--/end post-->

    <?php endwhile; else: ?>
    <p><?php _e('No Post Found','your_theme_text_domain'); ?></p> 

    <?php endif; ?>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top