【问题标题】: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】:

    按分类词查询自定义帖子类型


    此示例将假定:

    • 自定义帖子类型已在分类中注册,并且分类已在 '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; ?>
    

    【讨论】:

    • 谢谢!我会试一试,看看结果如何!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-03
    • 2013-06-22
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 1970-01-01
    相关资源
    最近更新 更多