【问题标题】:Get Page by TAG ID in Wordpress在 Wordpress 中按 TAG ID 获取页面
【发布时间】:2013-02-23 20:49:14
【问题描述】:

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

我尝试在谷歌搜索来实现这一点。这可能吗?

谢谢..

【问题讨论】:

    标签: php wordpress wordpress-theming tagging


    【解决方案1】:

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

    //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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-08
      • 2020-04-20
      • 2020-04-17
      • 2014-04-16
      • 1970-01-01
      • 2019-12-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多