WordPress REST API-超过10个帖子

kur*_*rtg 2 wordpress custom-post-type wp-api wordpress-rest-api

我搜索了此问题,并尝试了几种没有运气的解决方案。

我的主要路线在这里: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而不使用过滤器查询,但这也不起作用。任何帮助或见解,不胜感激!

And*_*ing 6

是的,您一次最多可以获取10条默认帖子。

只需将per_page参数添加到您的请求中即可。

示例:https//cnperformance.wpengine.com/wp-json/wp/v2/products/?per_page = 100

100是当前的最大限制!

更多信息:https : //developer.wordpress.org/rest-api/using-the-rest-api/pagination/


例如如何加载100多个项目在一次

在您的第一个请求之后,显示一个for循环和总页数信息:

https://github.com/AndreKelling/mapple/blob/master/public/js/mapple-public.js#L46