【问题标题】:List custom post type with certain tag (wordpress)列出具有特定标签的自定义帖子类型(wordpress)
【发布时间】:2013-06-30 20:51:12
【问题描述】:

所以这让我发疯了。

我可以轻松列出所有具有特定标签的帖子标题,如下所示:

<?php 
query_posts( 'tag=products' );
if ( have_posts() ) while ( have_posts() ) : the_post();
echo "<h1>" . the_title() . "</h1>";
endwhile; 
wp_reset_query(); ?>

但这仅适用于所有标准帖子。如果仅对某个自定义帖子类型(我的自定义帖子类型称为“产品”)进行此操作,我需要做的是。换句话说,它应该显示所有带有“webonly”标签的“产品”自定义帖子类型的标题。

任何建议都会有所帮助。

【问题讨论】:

    标签: wordpress tags custom-post-type


    【解决方案1】:

    显示所有添加 webonly 标签的帖子列表

    notice-tag = your tag taxonomy name
    
    terms in define your tag slug name
    
    'post_type'=>'notice',  in define your post type
    
    <?php 
        $args = array(
                'tax_query' => array(
                            array(
                                'taxonomy' => 'notice-tag',
                                'field' => 'slug',
                                'terms' => array( 'webonly' )
                            )
                    ),
                'post_type'=>'notice',
                'order'=>'ASC',
                'posts_per_page'=>-1
        );
        query_posts($args); ?>
        <?php while (have_posts() ) : the_post(); ?>
    
        <?php echo the_title(); ?>
    
        <?php endwhile; ?>
    

    【讨论】:

    • 宾果游戏。只需要在最后重置查询,现在一切都很好。非常感谢!
    • 我不确定为什么这是公认的答案。在上述查询中,“post_type”被忽略。如果您删除“tax_query”,则不会忽略“post_type”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    相关资源
    最近更新 更多