1

我有一个具有多种分类类型的自定义帖子类型。问题只集中在其中一个上。我需要显示所有已检查特色供应商分类的自定义帖子。目前,只有一个“特色”,但将来可能会有更多,例如“亮点”或“赞助商”或仅这些台词。但是,现在,我只需要浏览所有“供应商”自定义帖子类型,找到在“特色供应商”分类中选中“特色”的帖子类型。

我有一些帖子说这是不可能的,但它们要么来自 2.8,要么来自今年的第一年,我知道 WordPress 从那时起至少发布了一个更新。

提前致谢!!

4

1 回答 1

0

按分类术语查询自定义帖子类型


此示例将假定:

  • 自定义帖子类型已在分类中注册,并且分类已在'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; ?>
于 2010-09-22T08:36:41.650 回答