Col*_*una 17 php wordpress wordpress-theming wordpress-plugin
我必须脑死,我无法弄清楚如何获取所有帖子,$wp_query以便我可以为搜索结果创建一个小部件过滤器.
$wp_query->posts只给我将要显示在列表中的帖子,因此,如果posts_per_page设置为10,我只会得到10个帖子.我需要它们所以我可以对它们进行排序并根据搜索结果中的所有帖子显示过滤器.
有任何想法吗?
Gaj*_*ngh 27
将args中的posts_per_page参数设置为-1,这将返回wp_posts表中的所有帖子.例如
$args = array(
'posts_per_page' => -1,
'post_type' => 'post',
);
$the_query = new WP_Query( $args );
Run Code Online (Sandbox Code Playgroud)
现在你可以循环并获得帖子
while ( $the_query->have_posts() ) {
// go ahead
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29480 次 |
| 最近记录: |