Php 在wordpress上显示按标签归档的帖子?

Php 在wordpress上显示按标签归档的帖子?,php,wordpress,tags,Php,Wordpress,Tags,我想查询所有包含特定标签的帖子,因此,查看codex ref,它说类似这样的东西应该可以工作: $args = array( 'tag' => 'my-tag' ); $wp_query->query($args); while ( $wp_query->have_posts() ) : $wp_query->the_post(); endwhile; 但它总是返回false 我在阅读时不可能做到这一点,我必须使用has_标签,而我在所有帖子上都做了一段时间,

我想查询所有包含特定标签的帖子,因此,查看codex ref,它说类似这样的东西应该可以工作:

$args = array( 'tag' => 'my-tag' );
$wp_query->query($args);
while ( $wp_query->have_posts() ) :
    $wp_query->the_post();
 endwhile;
但它总是返回false

我在阅读时不可能做到这一点,我必须使用
has_标签
,而我在所有帖子上都做了一段时间,这是真的吗

你知道怎么做吗


谢谢,

非常简单,只需要阅读:


//这将开始循环,以使用标记发布帖子
//闭环
//如果不存在帖子,则加载错误


您是否尝试过使用特定的标记ID而不是名称?
<?php $your_query = new WP_query(' tag_id=###' );

    if ( $your_query->have_posts() ) : ?>

    // This begins the loop to post the posts with your tag
    <?php while ( $your_query->have_posts() ) : $your_query->the_post(); ?>
        <h2><?php the_title(); ?></h2>
    <?php endwhile; ?>
    // Closes loop

    <?php wp_reset_postdata(); ?>

<?php else : ?>
    // Loads error if no posts exists
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>