Retrieve index of acf field in a query loop

In Cwicly, is it possible to dynamically assign a value from a query loop to a function using a dynamic tag? How can we retrieve the index path (acf array) of a value inputted via the query loop for its subsequent modification with a hook or custom code?

Consider the following hierarchical structure of an ACF group field:

  1. Program
    1.1 Week
    1.1.1. Workout Exercise, Variant, Reps, Sets, Intensity, KG, “Done”.

To modify the “Done” field through a button click interaction and a custom function, I need to identify the index of “Done” along with its parent elements. What’s the best approach to accomplish this?

I maybe missing the point, but are you trying to modify Done field with WP Rest API from the frontend with javascript?

If so, you will at least need the post ID of the post its custom fields you want to modify. You can add a custom attribute to a block in your query template to hold the post ID. You can use the dynamic tag {id} for that as shown below.

Now you can target the post you want to modify with the button

There are probably other things missing. I couldn’t fully understand how your ACFs are setup, what post type you are querying, and what you mean by “ACF array” (repeater?).

Hope this helps…

Acf repeater is php array in the database . The structure is:
Fields (including done)

I’m not using rest API, I need the index of each repeater row to use acf funnction

Not sure if this helps but…

The {loop-index} dynamic tag will give you the row index of the current row in the current repeater. But as far as I know you can’t use the tag inside a function. If you are inside a function or using a Cwicly code block inside a repeater, then calling get_row_index() will return the index of the current row of the current repeater.

I knew about loop index but it doesn’t return parent index . I have to check about get row function but I’m pretty sure that it’s the same problem . @Louis Can you help me please ?

get_row_index() will return the index of the current row in the current repeated. It will not tell you the row of the parent. I wouldn’t say it’s a problem. It’s just how get_row_index() is designed to work.

You might not even need to know the index of the current row (or parent rows for that matter). You can get the Done field from within the last repeater (from a Cwicly block or a custom function) with ACF’s get_sub_field() function:

// get "Done" field of the current row in repeater
$done = get_sub_field('done');
// do stuff with "$done"
// ...
// to modify "Done", use update_sub_field()
update_sub_field('done', true);

Then again, I feel you need to give more details about how you intend to update “Done” ACF. You said that you are using a button for that. But what does the button trigger? You confirmed you are not using REST API to update your ACF value. Are you submitting a form? Do you intend to use query parameters for this?

The more details you provide, the better we can help you solve your problem. Screenshots will also help.

I know how to use ACF to update custom fields. The challenge lies in accessing the loop, as it becomes complicated without any reference to the parent repeater or its ancestors.

If I had the specific row that I want to modify, I could directly update the “Done” field by clicking on the form or a button that triggers a custom function through interactions with Cwicly and/or JavaScript.

Here is the hierarchical structure of an ACF group field:

  1. Program (Repeater)
    1.1 Week (Repeater)
    1.1.1 Workout (Repeater) Exercise, Variant, Reps, Sets, Intensity, KG, “Done” (Fields).

To update a field like “done,” I need to know at least the row of the “allenamento” repeater and the row of the “settimana” repeater.

Blocks placed under the Cwicly Repeater Block are rendered from inside the loop. Which means any custom code you write runs inside the loop as well.

Can I use dynamic tag as parameter for dynamic insert return function inside repeater ? Ex: