这是一个关于Wordpress API/wp-json的简单问题.我正在查询在Wordpress中使用某些类别过滤的一些数据.我的问题是如何控制从我的Get请求返回的结果数量...默认返回似乎返回大约11个最近的结果.有什么方法可以让它只返回1(最近),或100个帖子.我可以返回的最低和最高金额是多少.它的语法是什么?这是我的默认请求:
http://thisismywebsitewherewordpresslives.com/wp-json/posts?fiter[category_name]=Some Category Name I want to query&filter[order]=ASC
Run Code Online (Sandbox Code Playgroud) 我正在使用以下内容来获取帖子
http://demo.wp-api.org/wp-json/wp/v2/posts
默认情况下,这给了我 10 个帖子,这是在文档中提到的。
但我想要所有帖子而不必跟踪分页。
那可能吗?
如果没有,有没有办法运行 JavaScript 循环来获取所有帖子?
谢谢。
我搜索了此问题,并尝试了几种没有运气的解决方案。
我的主要路线在这里:https : //cnperformance.wpengine.com/wp-json/wp/v2/products?_embed
我安装了“ WP REST API过滤器参数”插件,以还原当REST API移至WordPress核心时删除的过滤器。
我试过了:https : //cnperformance.wpengine.com/wp-json/wp/v2/products?_embed&?filter[per_page]=-1
和
https://cnperformance.wpengine.com/wp-json/wp/v2/products?_embed&?filter[posts_per_page]=-1
我也在functions.php中尝试过
add_filter( 'rest_endpoints', function( $endpoints ){
if ( ! isset( $endpoints['/wp/v2/products'] ) ) {
return $endpoints;
}
unset( $endpoints['/wp/v2/products'][0]['args']['per_page']['maximum'] );
return $endpoints;
});
Run Code Online (Sandbox Code Playgroud)
参考在这里:https : //github.com/WP-API/WP-API/issues/2316
我已将posts_per_page的值设置为100,-1,没有区别。我还尝试仅添加参数'&posts_per_page = -1而不使用过滤器查询,但这也不起作用。任何帮助或见解,不胜感激!