Update sub row() (ACF)

Uit De Vliegende Brigade
Versie door Jeroen Strompf (overleg | bijdragen) op 1 aug 2022 om 11:13 (→‎Zie ook)
(wijz) ← Oudere versie | Huidige versie (wijz) | Nieuwere versie → (wijz)
Naar navigatie springen Naar zoeken springen

update_sub_row(): Updates a row of data for an existing Repeater or Flexible Content sub field value.

This function can be used inside or outside of a have_rows() loop. When used inside, the current row will be used to update the sub field value. When used outside, the rows and parents must be specified to target the correct value place.

Please note this function is used to modify a sub field value. To modify a parent field value, please use the update_row() function.

⇒ Lijkt niet goed te werken als het om alleen een subveld gaat c.q., een repeater met daarin maar 1 veld.

Syntaxis

update_sub_row($selector, $row, $value, [$post_id]) as boolean
  • $selector (required, string|array): The sub field name or key, or an array of ancestors and row numbers.
  • $row (required, integer): The row number to update.
  • $value (required, array): The new row data.
  • $post_id (optional, mixed): The post ID where the value is saved. Defaults to the current post.

Voorbeeld: Update binnen een have_rows()-loop

while (have_rows('add_code_to_head', 'option')):
   update_sub_row('line', 1, "Niet zo lang" );
endwhile;

Zie ook