0

I'm working on small, vue based SPA. I'm using axios to get data from api that I'm interested about. The problem is that parameters are not working in any way, the same happens in Postman (I tried Postman because I thought that there is an error in my code, but there is not). Let's say I want to get posts from category 12 and order them ascending. So what I would try is something like this:

http://api-address.com/wp-json/wp/v2/posts/?categories=12&order=asc

Call presented above returns posts in wrong order. I'm struggling with this and can't make it work - so frustrating that official documentation lacks real usage examples...

  • 1
    What's incorrect about the response you're receiving? You say it "just returns all posts from category with id=12", which sounds correct to me. Is the order wrong? By default posts are ordered by date, so this would return posts with the oldest first. Is that not what you're getting? – Jacob Peattie Jun 26 at 9:46
  • Thank You for Your reply. That was a mistake, I mean that those posts are not sorted in the way I want (ascending). – Sebastian Jun 26 at 10:15
  • 2
    When you say it's in the wrong order, what order is it in? Is it in descending order by date? Or something else? The only reason it wouldn't be sorting correctly is if you have a theme, plugin or other custom code that affects the ordering of posts. Do you still have the issue with a default theme and no plugins active? – Jacob Peattie Jun 26 at 10:19
1

If results should be ordered by a method other than the default asc or desc, you should also pass the orderby parameter. This gives you the ability to order by title, date, parent, type and many more that can be seen here.

For example, a request ordering the results a-z by title would be:

http://api-address.com/wp-json/wp/v2/posts/?categories=12&order=asc&orderby=title
0

@thomas answer is right Sometimes is parameter don't recognised by the API then it will be give the default response.

You need to provide some default argument to the API.

You can use your own custom rest route to the your site.

Sometimes you need authentication from the word wordpress like WP nouns and anothers. For POST request.

Wordpress rest API 2 support delete get post put.

In WordPress Codex you might get stuck.

  • OK, but I think OP is making a GET request to the posts endpoint, which doesn't need authentication, and passing standard parameters. – Rup Jun 28 at 17:58
  • Ya right you are saying true, i have also faced that issue. – Ronak J Vanpariya Jun 28 at 18:01

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.