admin管理员组文章数量:1122846
I got the following error, trying to call all posts or alle posts from a specific post type via the REST API:
/wp-json/wp/v2/posts
/wp-json/wp/v2/posts?page=1
/wp-json/wp/v2/posts?page=1&per_page=1
/wp-json/wp/v2/faq
The error which appears is:
{ "code": "rest_post_invalid_page_number", "message": "The page number requested is larger than the number of pages available.", "data": { "status": 400 } }
I got two posts within the custom post type and one normal post.
What causes this error?
I got the following error, trying to call all posts or alle posts from a specific post type via the REST API:
/wp-json/wp/v2/posts
/wp-json/wp/v2/posts?page=1
/wp-json/wp/v2/posts?page=1&per_page=1
/wp-json/wp/v2/faq
The error which appears is:
{ "code": "rest_post_invalid_page_number", "message": "The page number requested is larger than the number of pages available.", "data": { "status": 400 } }
I got two posts within the custom post type and one normal post.
What causes this error?
Share Improve this question edited Dec 5, 2018 at 22:46 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Dec 4, 2018 at 9:55 MaxMax 1763 silver badges15 bronze badges 6 | Show 1 more comment2 Answers
Reset to default 0I don't know why yet, but I had the same issue until I disabled a filter on pre_get_posts
.
What I'm doing here is retrieve all recipe
custom post type when I'm on the home page :
// add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query )
{
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', array( 'recipe' ) );
$query->set( 'posts_per_page', -1 );
return $query;
}
Try to know if you're hijacking a main query like I did, I'll do more research on the "why" :)
I had the same above issue. I disabled the 'pre_get_posts and it worked fine.
// add_action('pre_get_posts','pre_queries');
本文标签: Error restpostinvalidpagenumber trying to call Rest API
版权声明:本文标题:Error rest_post_invalid_page_number trying to call Rest API 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736293757a1929211.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
per_page
to limit the number of posts, like so:/wp-json/wp/v2/posts?per_page=3
- demo. That's for the standard post type, but should also work for custom post types. – Sally CJ Commented Dec 4, 2018 at 10:39