WordPress WP查询显示所有带有特定标签的帖子


Wordpress WP Query display all posts with specific tag

我相信这应该很简单,但似乎对我不起作用。

$query1 = new WP_Query('posts_per_page=-1'); // getting all posts works fine
$query1 = new WP_Query('tag=slug'); // getting the slug works fine

但是把这两者放在一起并没有发生。我试过:

$query1 = new WP_Query('posts_per_page=-1', 'tag=slug');

和。。。

$query1 = new WP_Query( array( 'posts_per_page' => -1, 'tag' => 'slug' ) );

没有运气。

尝试:

$query = new WP_Query( 'posts_per_page=-1&tag=cooking' );
echo '<pre>' . print_r( $query->posts, 1 ) . '</pre>'; // this line is for debugging purposes only.

您缺少与号"&"。

看:

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