I got the following error, trying to call all posts or alle posts from a specific post type via the REST API:


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?

  • What's your code? And you should use 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
  • I have no code written yet. I am just trying to get the result within the browser.
    – Max
    Commented Dec 4, 2018 at 10:55
  • Ok, but the error actually clearly suggests that there were no posts found for the request. Are you 100% sure the normal post you have is not private (and published)? If yes, then there's probably a plugin or custom code which filters the REST API response and excluding that post.
    – Sally CJ
    Commented Dec 4, 2018 at 11:26
  • I am absolutely sure that there are published posts. :/
    – Max
    Commented Dec 4, 2018 at 11:27
  • The only plugin activated is AdvancedCustomFieldsPro
    – Max
    Commented Dec 4, 2018 at 11:29

2 Answers 2


I 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');

  • Where's that from? That's not a default WordPress-core-supplied hook I don't think.
    – Rup
    Commented Nov 15, 2021 at 11:08
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Nov 15, 2021 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.