Support » Fixing WordPress » /wp-json/wp/v2/posts works only for one post per page

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello,

    It could be related to url parameters in my opinion. In your example the following urls:

    http://site.domain/wp-json/wp/v2/posts&per_page=1
    http://site.domain/wp-json/wp/v2/posts&per_page=2
    http://site.domain/wp-json/wp/v2/posts&per_page=1&page=2

    should be:

    http://site.domain/wp-json/wp/v2/posts?per_page=1
    http://site.domain/wp-json/wp/v2/posts?per_page=2
    http://site.domain/wp-json/wp/v2/posts?per_page=1&page=2

    so the first query parameter is always preceded with ? sign, not an ampersand. Although, /wp-json/wp/v2/posts should always return posts, if there are any. Try to turn off all the plugins and enable debug mode in your wp-config to see if there are any errors.
    Also, make sure that you don’t mix posts&pages – they’re different in WordPress and you might need to use /wp-json/wp/v2/pages for your purposes.

    Thanks

    Thread Starter fromgate

    (@fromgate)

    No, I made error but in question. Not in URL.

    Today I noticed another strange behavior:

    http://site.domain/wp-json/wp/v2/posts?per_page=3 – works fine

    But
    http://site.domain/wp-json/wp/v2/posts?per_page=3&page=2
    or http://site.domain/wp-json/wp/v2/posts?per_page=4
    does not work!

    And there’s no helpful info in wp-content/debug.log

    • This reply was modified 4 years, 7 months ago by fromgate.

    In your latest message you mentioned this url twice:
    http://site.domain/wp-json/wp/v2/posts?per_page=3
    both as working and not-working url. How it can be possible?
    Also, can you make sure that you have the following code in your wp-config.php

    define( 'WP_DEBUG', true );
     define( 'WP_DEBUG_DISPLAY', false );
     define( 'WP_DEBUG_LOG', true );
     define( 'SCRIPT_DEBUG', true );
     define( 'JETPACK_DEV_DEBUG', false );

    so it will save any errors in debug.log

    Thread Starter fromgate

    (@fromgate)

    Oh! I mean http://site.domain/wp-json/wp/v2/posts?per_page=4
    Adding only one post – and I got a empty page.

    Thanks for debug config. I will check it.

    Thread Starter fromgate

    (@fromgate)

    Omg!
    Something wrong with single post!

    This URLs works:

    http://site/wp-json/wp/v2/posts?per_page=1&page=1
    http://site/wp-json/wp/v2/posts?per_page=1&page=3
    http://site/wp-json/wp/v2/posts?per_page=1&page=2

    This one doesn’t:
    http://site/wp-json/wp/v2/posts?per_page=1&page=4

    And this works again:
    http://site/wp-json/wp/v2/posts?per_page=1&page=5

    • This reply was modified 4 years, 7 months ago by fromgate.

    Hi @fromgate,

    I seem to be having the same problem as you, where certain posts/pages are inaccessible via the API. I am getting a 200 status code for my requests, but completely blank content in the response (not even an empty JSON array). Did you make any progress with this problem, or are you still as stuck as I am?

    Thread Starter fromgate

    (@fromgate)

    It looks like issue is solved now (after updating to WP 4.8).

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘/wp-json/wp/v2/posts works only for one post per page’ is closed to new replies.