按Wordpress中的TAG ID获取页面


Get Page by TAG ID in Wordpress

所以我有一个php脚本,需要检索某个"页面",而不是一篇文章,而是一个页面,在wordpress中,我想检索一个指向特定标签的页面。我想知道如何检索某个页面,它唯一需要的参数是tag->term_id。

我试着在谷歌上搜索以获得这个结果。这可能吗?

谢谢。。

使用WP_Querypost_type设置为page来查询数据库中的页面。可以使用tag_id参数按标记缩小范围。使用设置为1posts_per_page将其限制为一个结果。

//narrow down your query with $args
$args = array('post_type'=>'page', 'tag_id'=>3, 'posts_per_page'=>1);
// The Query
$the_query = new WP_Query( $args );
// The Loop
while ( $the_query->have_posts() ) :
    $the_query->the_post();
    echo '<li>' . get_the_title() . '</li>';
endwhile;

http://codex.wordpress.org/Class_Reference/WP_Query