WP-API get posts and order them by a descending order
Asked Answered
M

1

5

I am trying to grab posts and order them by date, in a descending order.

I am talking about this API: https://github.com/WP-API/WP-API

I tried:

http://url.com/json/wp-json/wp/v2/posts?filter[order]=DESC

http://url.com/json/wp-json/wp/v2/posts?order=desc

Neither of them work.

But this, for example, works fine:

http://url.com/json/wp-json/wp/v2/posts?filter[cat]=3

Any idea?

Marmite answered 12/4, 2016 at 11:1 Comment(1)
Are you sure, it's not working? I've tried http://demo.wp-api.org/wp-json/wp/v2/posts?order=asc and http://demo.wp-api.org/wp-json/wp/v2/posts?order=desc - seems to be working fine. According to their docs, it should work: v2.wp-api.org/reference/posts.Electrotonus
C
23

You need to use orderby e.g.

http://url.com/json/wp-json/wp/v2/posts?filter[orderby]=wpdb_fieldname&order=desc

In your case

http://url.com/json/wp-json/wp/v2/posts?filter[orderby]=date&order=desc

More details here: http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

Carat answered 19/4, 2016 at 6:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.