WordPress 3.0.1 使用自定义分类查询自定义帖子类型

发布于 2024-09-25 01:18:12 字数 252 浏览 9 评论 0原文

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

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

提前致谢!!

I have a custom post type with multiple taxonomy types. The issue is focused around just one of them.
I need to display all custom posts that have a taxonomy from featured-vendors checked. Right now, there is just one "featured" , but there may be more in the future, such as "highlight" or "sponsor" or something alone those lines.
But, for now, I just need to go through all the "vendors" custom post type, find ones with "featured" checked inside of the "featured-vendors" taxonomy.

I have some some posts out there that state it's not possible, but they were either from 2.8 or from the very first of this year and I know WordPress has released at least one update since then.

Thanks in advance!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天赋异禀 2024-10-02 01:18:12

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

此示例将假设:

  • 自定义帖子类型已使用分类注册,并且分类已使用 'query_var' =>true'hierarchial 注册'=>正确

  • “选中”的术语将是父级,任何新术语都可以稍后作为子级添加。

代码:

 <?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; ?>

Query Custom Post Types by Taxonomy Term

This sample will assume:

  • the custom post type was registered with the taxonomy and the taxonomy was registerd with 'query_var' =>true and 'hierarchial' => true

  • The "checked" term will be the parent and any new ones can be added later on as children.

The Code:

 <?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; ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文