Wordpress WP_Query显示具有特定标记的所有帖子

时间:2014-11-25 16:16:50

标签: php wordpress

我确定这应该很简单,但似乎并不适合我。

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

但是把2放在了一起。我试过了:

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

和...

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

没有运气。

1 个答案:

答案 0 :(得分:1)

尝试:

$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.

您错过了&符号&amp;&#39;。

请参阅:

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

相关问题