Get the key name

Hi there,

I’m trying to update a repeater filed in ACF (Wordpress).

I need to add a metadata (custom field) with the name and value:

The problem with this configuration is that it will pass the “heure” value (here: 16h00), not the key name (and path).

Is there a way to get the key’s name ?

I tried to manually write the path:
“liste_rendez-vous.heure”
“liste_rendez-vous[ ]:heure”
“liste_rendez-vous:{heure}”
etc.
But nothing seems to work

Any help would be much appreciated !

To get the key names in a collection, you can use the keys() built-in function.

Example collection “item”:

Use keys():

You get the keys:

Screenshot_2023-09-22_220957 (2)

2 Likes

Thanks for your answer.

Unfortunately, it returns an empty key, see below:
Capture d'écran 2023-09-22 165352

Should I add a get() function after that ?

You’ll have to select the parent array, not the child item, to get all the keys. Then, you can iterate through or get the first item.

Alternatively, you can use toArray() built-in function to get both the keys and values:

Screenshot_2023-09-22_220907

2 Likes

I tried like this:

But got 0 as a key
Capture d'écran 2023-09-22 170031

I also tried with the parent acf, but it doesn’t display the sub-child keys from “liste_rendez-vous”

Welcome to the Make community!

Could you please provide the input/output bundles of the modules by running the scenario, then clicking the bubble on the top-right of each module, taking screenshots of, and copying the contents into this discussion thread:

Screenshot_2023-08-29_100800

This will allow others to better assist you. Thanks!

2 Likes

Here is the content of the input:

[
    {
        "id": 28900,
        "meta": [
            {
                "name": "0",
                "value": "18h20"
            }
        ],
        "type": "permanence"
    }
]

And the output:

[
    {
        "id": 28900,
        "date": "2023-09-15T13:50:55.000Z",
        "guid": "https://notaires.455.ch/?post_type=permanence&p=28900",
        "password": "",
        "slug": "29-09-2023-yverdon",
        "status": "publish",
        "type": "permanence",
        "type_for_mapping": "permanence",
        "link": "https://notaires.455.ch/permanence/29-09-2023-yverdon/",
        "title": "29/09/2023 - Yverdon",
        "content": {
            "raw": "",
            "rendered": "",
            "protected": false,
            "block_version": 0
        },
        "template": "",
        "meta": {
            "inline_featured_image": false
        },
        "permalink_template": "https://notaires.455.ch/permanence/%pagename%/",
        "generated_slug": "29-09-2023-yverdon",
        "acf": {
            "date_permanence": "20230929",
            "lieu_de_la_permanence": "Yverdon",
            "rendez-vous": "16h00,",
            "liste_rendez-vous": [
                {
                    "heure": "16h00",
                    "prenom_nom": "Test Test",
                    "email": "test@test.ch",
                    "telephone": "0211231212"
                }
            ],
            "notaire": [
                28943
            ],
            "rdv": 28958
        },
        "date_de_la_permanence": null,
        "_date_de_la_permanence": null,
        "rendez-vous": "16h00,",
        "_rendez-vous": "field_6502b60999bdd",
        "_links": {
            "self": [
                {
                    "href": "https://notaires.455.ch/wp-json/wp/v2/permanence/28900"
                }
            ],
            "collection": [
                {
                    "href": "https://notaires.455.ch/wp-json/wp/v2/permanence"
                }
            ],
            "about": [
                {
                    "href": "https://notaires.455.ch/wp-json/wp/v2/types/permanence"
                }
            ],
            "acf:post": [
                {
                    "embeddable": true,
                    "href": "https://notaires.455.ch/wp-json/wp/v2/rendez-vous/28958"
                }
            ],
            "wp:attachment": [
                {
                    "href": "https://notaires.455.ch/wp-json/wp/v2/media?parent=28900"
                }
            ],
            "wp:action-publish": [
                {
                    "href": "https://notaires.455.ch/wp-json/wp/v2/permanence/28900"
                }
            ],
            "wp:action-unfiltered-html": [
                {
                    "href": "https://notaires.455.ch/wp-json/wp/v2/permanence/28900"
                }
            ],
            "curies": [
                {
                    "name": "wp",
                    "href": "https://api.w.org/{rel}",
                    "templated": true
                }
            ]
        },
        "modifiedDate": "2023-09-22T13:00:22.000Z",
        "excerpt": null
    }
]

Looks like you need: keys(first(array))

Screenshot_2023-09-25_120923

You can use an iterator to loop through each key name, or use first() to get “heure”

2 Likes