airesvsg / acf-to-rest-api

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

Return ACF field label and other data in API #252

Open oktalk opened 6 years ago

oktalk commented 6 years ago

It seems like a bug that only the value is returned in the API for ACF fields. The ACF API JSON data currently resembles this:

...
acf: {
    ...
    length: "22",
    engine_drive_type: "automatic"
    ....
}
...

Why can't it look like this:

acf: {
    ....
    length: {
        label: "Length",
        name: "length",
        type: "text",
        value:"22",
        ...
    },
    engine_drive_type: {
        label: "Engine Drive Type",
        name: "engine_drive_type",
        type: "text",
        value: "automatic",
        ...
    }
    ....
}
airesvsg commented 6 years ago

Hi @oktalk,

Can you export your fields groups to me?

Custom Fields ( menu item ) > Tools > Export Field Groups

Thanks

oktalk commented 6 years ago

Wow! This has everything. Why isn't all this data in the API?

[
    {
        "key": "group_5abe8e581db19",
        "title": "Information",
        "fields": [
            {
                "key": "field_5ace211a23431",
                "label": "Equipment Information",
                "name": "equipment_information",
                "type": "group",
                "instructions": "",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "layout": "block",
                "sub_fields": [
                    {
                        "key": "field_5abe9121dbfde",
                        "label": "Location",
                        "name": "location",
                        "type": "text",
                        "instructions": "",
                        "required": 0,
                        "conditional_logic": 0,
                        "wrapper": {
                            "width": "",
                            "class": "",
                            "id": ""
                        },
                        "default_value": "",
                        "placeholder": "",
                        "prepend": "",
                        "append": "",
                        "maxlength": ""
                    },
                    {
                        "key": "field_5abe8e79dbfdc",
                        "label": "Condition",
                        "name": "condition",
                        "type": "select",
                        "instructions": "",
                        "required": 0,
                        "conditional_logic": 0,
                        "wrapper": {
                            "width": "",
                            "class": "",
                            "id": ""
                        },
                        "choices": {
                            "Excellent": "Excellent",
                            "Good": "Good",
                            "Fair": "Fair",
                            "Poor": "Poor"
                        },
                        "default_value": [
                            "Good"
                        ],
                        "allow_null": 1,
                        "multiple": 0,
                        "ui": 0,
                        "ajax": 0,
                        "return_format": "value",
                        "placeholder": ""
                    },
                    {
                        "key": "field_5abe914ddbfdf",
                        "label": "Serial\/VIN",
                        "name": "serial",
                        "type": "text",
                        "instructions": "",
                        "required": 1,
                        "conditional_logic": 0,
                        "wrapper": {
                            "width": "",
                            "class": "",
                            "id": ""
                        },
                        "default_value": "",
                        "placeholder": "",
                        "prepend": "",
                        "append": "",
                        "maxlength": ""
                    },
                    {
                        "key": "field_5abe90cbdbfdd",
                        "label": "Hours\/Miles",
                        "name": "hours",
                        "type": "number",
                        "instructions": "",
                        "required": 0,
                        "conditional_logic": 0,
                        "wrapper": {
                            "width": "",
                            "class": "",
                            "id": ""
                        },
                        "default_value": "null",
                        "placeholder": "",
                        "prepend": "",
                        "append": "",
                        "min": "",
                        "max": "",
                        "step": ""
                    },
                    {
                        "key": "field_5ac532fcfea0a",
                        "label": "Make",
                        "name": "make",
                        "type": "text",
                        "instructions": "",
                        "required": 1,
                        "conditional_logic": 0,
                        "wrapper": {
                            "width": "",
                            "class": "",
                            "id": ""
                        },
                        "default_value": "Atlas Copco",
                        "placeholder": "",
                        "prepend": "",
                        "append": "",
                        "maxlength": ""
                    },
                    {
                        "key": "field_5abea0c46ea2e",
                        "label": "Model",
                        "name": "model",
                        "type": "text",
                        "instructions": "",
                        "required": 1,
                        "conditional_logic": 0,
                        "wrapper": {
                            "width": "",
                            "class": "",
                            "id": ""
                        },
                        "default_value": "",
                        "placeholder": "",
                        "prepend": "",
                        "append": "",
                        "maxlength": ""
                    },
                    {
                        "key": "field_5ac532c953a19",
                        "label": "Year",
                        "name": "year",
                        "type": "number",
                        "instructions": "",
                        "required": 0,
                        "conditional_logic": 0,
                        "wrapper": {
                            "width": "",
                            "class": "",
                            "id": ""
                        },
                        "default_value": "",
                        "placeholder": "",
                        "prepend": "",
                        "append": "",
                        "min": "",
                        "max": "",
                        "step": ""
                    },
                    {
                        "key": "field_5b045fb70afd8",
                        "label": "New year field",
                        "name": "new_year_field",
                        "type": "text",
                        "instructions": "",
                        "required": 0,
                        "conditional_logic": 0,
                        "wrapper": {
                            "width": "",
                            "class": "",
                            "id": ""
                        },
                        "default_value": "",
                        "placeholder": "",
                        "prepend": "",
                        "append": "",
                        "maxlength": ""
                    }
                ]
            }
        ],
        "location": [
            [
                {
                    "param": "post_type",
                    "operator": "==",
                    "value": "inventory"
                }
            ]
        ],
        "menu_order": 0,
        "position": "normal",
        "style": "default",
        "label_placement": "top",
        "instruction_placement": "label",
        "hide_on_screen": "",
        "active": 1,
        "description": ""
    }
]
stasonn777 commented 3 years ago

Hello how did you solve the problem?