WordPress REST API order by meta_value

Another quick tip here, for future reference.

I needed to sort the custom posts in a REST API response by a meta value, something like this:

https://www.timrosswebdevelopment.com/wp-json/wp/v2/accommodation?orderby=number_of_beds

Where number_of_beds is a field that has been added using Advance Custom Fields.

The problem is the REST API only allows certain core fields to be used for the orderby param. See my other post on adding REST API orderby custom values for more info. So the question was how to add another.

Continue reading “WordPress REST API order by meta_value”