wordpress

Get all categories, custom field values in Wordpress query?


I've setup an API endpoint on a Wordpress site I'm working on, but the posts I'm retrieving have quite a bit of associated data, I think doing a query to get the posts then running the posts through a loop and getting this data will be too intensive, is there a catch all that can get all meta data at the same time as getting the posts?


Solution

  • If you're using REST API, you can use the function register_rest_field to add fields to responses. And then you can query all custom fields to put them in the responses.

    If you're using a plugin like Meta Box to create custom fields, then you can use its free extension MB REST API to pull all the custom fields into REST API responses for you.