Search code examples
jsonwordpressrestadvanced-custom-fieldswp-api

Include categories custom fields in REST api


I am working with Advanced custom fields, where I add an image selector for categories in wp - But I can't see the data in my JSON response for categories? I have tried to use several plugins to do the same, but That haven't worked either -

I am using ACF to rest plugin to include acf fields in the response, which works fine on custom post types - where it creates an array field called "acf" This field is not created in my categories though - Am i missing a function to use it in taxonomies?

examples.

domain.com/wp-json/wp/v2/recipies (a custom post type)

returns everything including acf.

domain.com/wp-json/v2/categories (a texonomy)

returns all of the categories, but nothing about acf

domain.com/wp-json/wp/v2/categories/37 (a single category)

returns the category but nothing about acf.

domain.com/wp-json/wp/v2/categories/37?_embed[0] (way of getting all embedded stuff)

Does not show acf

Hope that you can put me on the right path.


Solution

  • To anybody who is interested, and runs into this problem.

    I talked to the developer of acf-to-rest, and there is a bug in version 2, where it doesn't save taxonomies correctly - It is fixed in version 3, but you can't update it yet through wordpress, since it is still in beta -

    Redownload the plugin and go into your wp-config file here you need to define that you are going to use version 3. paste this line into the wp-config file

     define('ACF_TO_REST_API_REQUEST_VERSION', 3);
    

    The endpoints has been rewritten, so you also need to read up on that if you are using the acf endpoints for updating etc.

    To read more about the bug, go github page

    To read about the end points - go here

    I hope that this will help somebody in the future.