airesvsg / acf-to-rest-api

Exposes Advanced Custom Fields Endpoints in the WordPress REST API
https://wordpress.org/plugins/acf-to-rest-api/
1.33k stars 110 forks source link

Duplicated fields in REST API when using clone field #71

Closed dmajka closed 8 years ago

dmajka commented 8 years ago

I'm not sure if this is on the ACF or the acf-to-rest-api plugin side of things. I'm using a clone field in ACF Pro 5.4.5. All of my fields which are in clone groups are getting duplicated in the REST API, under an object named after the clone group. Like this:

"acf": {
      "test_text": "<p>Just some test text</p>",  
      "project_total_cost": "10",  
      "project_total_match": "20",  
      "fundraising_total_goal": "30",  
      "funding_private_by_year": false, 
      "funding_public_by_year": false, 
      "funding_impact_by_year": false, 
      "funding_notes": "<p>Funding notes go here</p>\n", 
      "budget_notes": "<p>Budget notes go here.</p>\n", 
      "fundraising_clone_group": { 
        "project_total_cost": "10", 
        "project_total_match": "20", 
        "fundraising_total_goal": "30", 
        "funding_private_by_year": false, 
        "funding_public_by_year": false, 
        "funding_impact_by_year": false, 
        "funding_notes": "<p>Funding notes go here</p>\n", 
        "budget_notes": "<p>Budget notes go here.</p>\n" 
      },

In the example above, I have a set of fields in a clone field called “fundraising_clone_group”. In the REST JSON, those fields are shown within an object named after the clone group (so acf.fundraising_clone_group.project_total_cost), but also flattened, at the acf root key: (e.g. acf.project_total_cost).

Has anyone else had this problem? I’m wondering if it’s something that should be fixed on the ACF to REST plugin side, or within ACF itself.

airesvsg commented 8 years ago

Hi @dmajka, This error probably in ACF. I'll test soon. Thanks

airesvsg commented 8 years ago

Hi @dmajka, This is not a error, but is how acf return the data. You can use the filter acf/rest_api/{type}/get_fields to remove duplicate data. Thanks