WordPress get_post();仅返回 5 个条目
Wordpress get_post(); Only Returning 5 Entries
这让我发疯试图弄清楚:在我的插件中,我有一个部分可以从数据库中提取所有条目 - 我们会说所有帖子,但我也显示页面和类别 - 使用这一行代码:
$args_posts = array(
'numberposts' => -1,
'suppress_filters' => true
);
$posts = get_pages($args_posts);
foreach ( $pages as $page ) {
//formatting & display
}
...然后使用 foreach() 语句对其进行循环、格式化和回显。
我遇到的问题是它在我的服务器上运行良好,但是当我让朋友尝试时它只显示 5 个帖子。它需要工作的环境最终将有几千个条目。最初,问题也存在于我身上,但我没有提供 get_posts()
的参数 - 我只是使用 $posts = $get_pages()
将其设置为变量本身,一旦我添加了它解决的参数。但是我的朋友仍然只看到 5 个条目显示,即使没有浏览器缓存或服务器缓存并且脚本中的其他更改正在通过。
提前致谢!
根据 Wordpress 文档:
Number
(integer) Sets the number of Pages to list. This causes the SQL LIMIT value to be defined. Default to no LIMIT. This parameter was
added with Version 2.8. Note: get_posts() uses the parameter
'numberposts' instead of 'number'. Second Note: it doesn't work if
used together with 'child_of'. Instead use 'parent' and set
'hierarchical' to false.
Link:
Documentation
换句话说,将 numberposts
更改为 number
这让我发疯试图弄清楚:在我的插件中,我有一个部分可以从数据库中提取所有条目 - 我们会说所有帖子,但我也显示页面和类别 - 使用这一行代码:
$args_posts = array(
'numberposts' => -1,
'suppress_filters' => true
);
$posts = get_pages($args_posts);
foreach ( $pages as $page ) {
//formatting & display
}
...然后使用 foreach() 语句对其进行循环、格式化和回显。
我遇到的问题是它在我的服务器上运行良好,但是当我让朋友尝试时它只显示 5 个帖子。它需要工作的环境最终将有几千个条目。最初,问题也存在于我身上,但我没有提供 get_posts()
的参数 - 我只是使用 $posts = $get_pages()
将其设置为变量本身,一旦我添加了它解决的参数。但是我的朋友仍然只看到 5 个条目显示,即使没有浏览器缓存或服务器缓存并且脚本中的其他更改正在通过。
提前致谢!
根据 Wordpress 文档:
Number
(integer) Sets the number of Pages to list. This causes the SQL LIMIT value to be defined. Default to no LIMIT. This parameter was added with Version 2.8. Note: get_posts() uses the parameter 'numberposts' instead of 'number'. Second Note: it doesn't work if used together with 'child_of'. Instead use 'parent' and set 'hierarchical' to false.
Link: Documentation
换句话说,将 numberposts
更改为 number