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:


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”

WordPress REST API post orderby custom value

Ordering posts by menu_order doesn’t work out of the box with the WP REST API. To enable this you need to add a filter to rest_{post_type}_collection_params for each post type you want to order by menu_order.

Continue reading "WordPress REST API post orderby custom value"