0

I'm having an issue with the server I'm working off of ignoring any parameters I send to the REST API. My local environment works perfectly, but for some reason the other environments don't. I work with a DevOps team, so I'm trying to gather as much information as I can to pass on to them to help them fix the problem.

Examples of endpoints I've tried hitting:

/wp-json/wp/v2/posts?per_page=2

/wp-json/wp/v2/posts?post_status=publish&page=4&posts_per_page=1&filter[posts_per_page]=1

/wp-json/wp/v2/posts?filter[posts_per_page]=2

/wp-json/wp/v2/posts?page=1&per_page=1&filter[s]=blah

Regardless of the endpoint I'm trying to hit the Headers link that is always returned is

Link →<https://myurl.com/wp-json/wp/v2/posts?q&page=2>; rel="next"

I found this post about nginx configuration issues: http://v2.wp-api.org/guide/problems/#query-parameters-are-ignored and changed the try_files line but the problem persists.

If anyone else has encountered this issue and has any tips for fixing it I would really appreciate it!

  • I'm pretty sure its a mapping/configuration issue with nginx. Those requests need to be passed on to Apache or whatever is servicing the php requests. Where are the errors coming from - nginx, Apache, WP? – user42826 Dec 29 '16 at 23:06
  • There aren't actually any errors, it's just not accepting any filters/parameters. The server is nginx. No matter what the parameters I pass are, the Headers Link that is always returned is https://myurl.com/wp-json/wp/v2/posts?q&page=2>; rel="next" – jenkma02 Jan 3 '17 at 15:54
  • Do you have any caching plugins enabled? Its possible the caching is returning the last cached data (ignores parameters). Most caching plugin allow you to configure urls not to cache. – user42826 Jan 3 '17 at 17:32
  • I did, but i disabled it and the problem persists. – jenkma02 Jan 3 '17 at 18:00
  • Is this only occurring with the REST API, or with other pages as well? (Try /?s=some+query for example.) – Ryan McCue Jan 5 '17 at 1:52
0

If your virtual host looks like this:

try_files $uri $uri/ /index.php$args;

change it to this:

try_files $uri $uri/ /index.php$is_args$args;

Adding $is_args (which will print a ? character if query arguments are found) will allow WordPress to properly receive and interpret the query parameters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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