post loop

时间:2015-09-16 00:38:26

标签: wordpress tags

如何在WP_Query()中添加多个标记。所以,我有三个标签:

  1. 名字(标签ID =" 10")
  2. 中间名(标签ID =" 20")
  3. 姓氏(标签ID =" 30")

    $args = array( 
     'post_type' => 'post',
        'paged'=>$paged,
        'posts_per_page' => 15,             
        'orderby' => 'date',
        **'tag_id' =>  array(10,20,30),**           
        'order' => 'DESC'
        );
    
  4. 当然上面不起作用。

    如何显示多个标签的帖子?

    谢谢!

2 个答案:

答案 0 :(得分:2)

有一个tag__in参数专门用于此:

$args = array( 
    'post_type' => 'post',
    'paged'=> $paged,
    'posts_per_page' => 15,             
    'orderby' => 'date',
    'tag__in' =>  array(10,20,30),
);

答案 1 :(得分:2)

如果你正在使用WP_Query,那么你可以这样做。

asadmin redeploy --keepstate=true --name=taskee-1.0-SNAPSHOT target/taskee-1.0-SNAPSHOT.war

OR

//Display posts that are tagged with both tag id 37 and tag id 47:
$query = new WP_Query( array( 'tag__and' => array( 37, 47 ) ) );

有关详情,请访问官方链接https://codex.wordpress.org/Class_Reference/WP_Query