2

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!

13
  • 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? Commented Dec 29, 2016 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" Commented Jan 3, 2017 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. Commented Jan 3, 2017 at 17:32
  • I did, but i disabled it and the problem persists. Commented Jan 3, 2017 at 18:00
  • Is this only occurring with the REST API, or with other pages as well? (Try /?s=some+query for example.) Commented Jan 5, 2017 at 1:52

1 Answer 1

5

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

2
  • 1
    I'm a support representative and I just worked through a support ticket with a user where this answer resolved the issue for them. This would be useful to add to any WordPress/Nginx configuration docs like this one for example: wordpress.org/support/article/nginx Commented Sep 4, 2021 at 14:39
  • I'm glad something I've wrote helps someone after 6 years Commented Sep 18, 2021 at 9:03

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.