Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WP-API get posts and order them by a descending order

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?

like image 727
Ariel Weinberger Avatar asked Apr 12 '16 11:04

Ariel Weinberger


1 Answers

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

like image 159
brianlmerritt Avatar answered Sep 23 '22 02:09

brianlmerritt