【问题标题】:WordPress 3.0.1 Query Custom Post Type with Custom TaxonomyWordPress 3.0.1 使用自定义分类查询自定义帖子类型
【发布时间】:2014-10-07 07:18:34
【问题描述】:
我有一个包含多种分类类型的自定义帖子类型。问题只集中在其中一个上。
我需要显示所有已检查特色供应商分类的自定义帖子。目前,只有一个“特色”,但将来可能会有更多,例如“亮点”或“赞助商”或仅这些台词。
但是,现在,我只需要检查所有“供应商”自定义帖子类型,找到在“特色供应商”分类中选中“特色”的帖子。
我有一些帖子说这是不可能的,但它们要么是从 2.8 开始,要么是从今年年初开始的,我知道 WordPress 从那时起至少发布了一个更新。
提前致谢!!
【问题讨论】:
标签:
wordpress
custom-post-type
taxonomy
【解决方案1】:
按分类词查询自定义帖子类型
此示例将假定:
代码:
<?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; ?>