Support

Account

Home Forums Feature Requests REST API

Solved

REST API

    • wube

    • September 20, 2015 at 1:51 am

    Some of you probably already know http://v2.wp-api.org/
    The following quote explains the reason why such a plugin was made and what is it for:

    WordPress is moving towards becoming a fully-fledged application framework, and we need new APIs. This project was born to create an easy-to-use, easy-to-understand and well-tested framework for creating these APIs, plus creating APIs for core.

    It would be great if ACF had REST API as well. At the moment we can only access custom fields via standard post meta. As you know it’s not the most convienient way to get ACF data.

    I know it is not a trivial case, but is there any chance to implement such a feature in ACF?

  • +1

    • airesvsg

    • September 25, 2015 at 1:58 pm

    Hi wube,

    you can use the plugin ACF to REST API:

    GitHub: https://github.com/airesvsg/acf-to-rest-api/

    WordPress.org: http://www.wordpress.org/plugins/acf-to-rest-api

    • effigy

    • December 8, 2015 at 12:26 am

    Hi Guys

    I have installed the ACF to WP REST API plugin but it only seems to work with GET requests, is there a way to use REST API to POST or PUT data into existing ACF fields?

  • Hi Effigy,

    Thanks for using my plugin.

    I’ll implement when they published the final version of the plugin WP REST API, it’s still in beta.

    https://github.com/airesvsg/acf-to-wp-rest-api/issues/2

    • effigy

    • December 8, 2015 at 12:50 am

    Hi Airesvsg,

    Is there a timeframe for the final version of WP REST API?

    in the meantime, do you know if there is there a work around to get data into ACF fields via the API ?

    Cheers

  • Hi,

    It should have a timeframe, but I do not know to inform.

    I do not know, I sent an email to Eliot, but was talking about the plugin ( ACF to WP REST API ), I will write another asking about it.

    Cheers

    • effigy

    • December 8, 2015 at 1:14 am

    Thanks Airesvsg, much appreciated.

    • hallwrk

    • December 12, 2015 at 4:28 am

    Hi, I’m very eager to use ACF pro with wp-api. I’m currently trying to get it set up using @airesvsg ‘s plugin; ACF to WP REST API, however it doesn’t seem to work with the development versions of wordpress, nor version 4.4. I don’t see the ‘acf’ key on the json output at all after trying a lot of various things(disabling, re-enabling, re-installing, enabling options page, deleting posts and custom fields and setting up again etc.)

    Would be very awesome if this became a part of ACF pro in the near future, as I’m eager to use it on four current projects.

    @airesvsg Would it be possible to get some quick pointers on what the issue might be with my setup? Is it the wp version, or have I missed something?
    Thanks for awesome plugins!
    h

  • Hi @hallwrk,

    You get some response when you accessing the url below?

    http://my-domain/wp-json/acf

    Cheers

    • hallwrk

    • December 12, 2015 at 5:32 am

    I get no route 404:
    http://gigil.berlin/current/xjazz/wp-json/acf

  • OK, @hallwrk.

    I’ll investigate this error.

    • hallwrk

    • December 12, 2015 at 5:44 am

    Could it be related to mod rewrite? Currently, permalinks are set to /%category%/%postname%
    But it’s funny that the rest of the api works fine in that case…

    • hallwrk

    • December 12, 2015 at 5:45 am

    Thank you for looking into it. Much appreciated!

  • @hallwrk which directory you installed the plugin?

    [404] http://gigil.berlin/current/xjazz/wp-content/plugins/acf-to-wp-rest-api/

    • hallwrk

    • December 12, 2015 at 6:04 am

    That was the name of the extracted folder. Could that be it?

  • @hallwrk you are using another plugin 😀

    You can download my plugin on the links below:

    https://wordpress.org/plugins/acf-to-wp-rest-api/

    or

    http://github.com/airesvsg/acf-to-wp-rest-api

    • hallwrk

    • December 12, 2015 at 6:18 am

    Haha, omg. Thanks… It will probably work now then 🙂

  • 🙂

  • Hi @hallwrk,

    I saw that isn’t listing yet, try the steps below:

    1- Access the permalinks settings ( Settings > Permalinks );
    2- Click the Save Changes button.

    • hallwrk

    • December 15, 2015 at 2:44 am

    Hi @airesvsg! Sorry, was offline over the weekend.
    The plugin is working wonderfully. I just have it running locally so far.
    Thank you!

    • hallwrk

    • December 15, 2015 at 4:36 am

    Just a small update on this.
    I ended up not using a plugin at all, but instead just adding the ACF fields by batch like this:

    add_action( 'rest_api_init', 'slug_register_acf' );
    function slug_register_acf() {
      $post_types = get_post_types(['public'=>true], 'names');
      foreach ($post_types as $type) {
        register_api_field( $type,
            'acf',
            array(
                'get_callback'    => 'slug_get_acf',
                'update_callback' => null,
                'schema'          => null,
            )
        );
      }
    }
    function slug_get_acf( $object, $field_name, $request ) {
        return get_fields($object[ 'id' ]);
    }
    

    This appends a key called “acf” to the rest api output for all public post types.
    Will be easier to customise too if you only want certain fields to be exposed.

  • Hi @hallwrk,

    you can use filter, see below how to use.

    https://github.com/airesvsg/acf-to-wp-rest-api#filter

    add_filter( 'acf_to_wp_rest_api_post_data', function( $data, $object, $context ) {
        if ( isset( $data['type'] ) && 'my_post_type' == $data['type'] && isset( $data['acf'] ) ) {
          unset( $data['acf'] );
        }
        return $data;
    }, 10, 3 );
    • hallwrk

    • December 15, 2015 at 4:59 am

    Thanks! I was looking at that, and then when I updated the WP REST API to Version 2.0-beta9, it broke your plugin. Looks like they changed the structure in the last release slightly. I’m looking forward to the release version of the API and will revisit your plugin when it is ready, but for now I think I’ll have to stick to the method in the WP REST API documentation to reduce version dependency.

Viewing 25 posts - 1 through 25 (of 46 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.