times / acf-to-wp-api

Puts all ACF fields from posts, pages, custom post types, attachments and taxonomy terms, into the WP-API output under the 'acf' key
http://wordpress.org/plugins/acf-to-wp-api/
MIT License
203 stars 24 forks source link

Nested ACF fields #18

Closed cpeddecord closed 9 years ago

cpeddecord commented 9 years ago

Hello! Was wondering if it was possible to get nested ACF fields within a repeater or otherwise. And if possible, how many levels of nesting could one go before it became ludicrous?

chrishutchinson commented 9 years ago

Hey @cpeddecord,

I'm not sure I fully understand what you're expecting. Could you post your ACF configuration and the expected API output?

cpeddecord commented 9 years ago

Hey @chrishutchinson!

the post I'm looking at spits out its json similar to this (other keys removed for brevity):

{
  "ID": 123,
  "acf": {
    "flexible_content": [
      "acf_fc_layout": "relationship_object",
      "single_post": {
        "ID": 456,
        "post_content": "Such Content"
      }
    ]
  }
}

In an ideal world, the nested post (ID: 456) in the flexible content would also return its own acf field as well.

{
  "ID": 123,
  "acf": {
    "flexible_content": [
      "acf_fc_layout": "relationship_object",
      "single_post": {
        "ID": 456,
        "post_content": "Such Content",
        "acf": {
          "acf_text": "Hello World"
        }
      }
    ]
  }
}
chrishutchinson commented 9 years ago

Hey @cpeddecord,

This has cropped up before in #16 and I made the call not to include those fields for various reasons, which I've listed in that issue log.

Hopefully that doesn't prevent you from using the plugin, particularly as my suggested approach is to make a secondary request to the WP-API to get that data.