[Resolved] How to programmatically add another value of a repeating custom field?
This thread is resolved. Here is a description of the problem and solution.
Problem:
Posts have a repeating custom field. How in PHP can you add additional instances of the field?
Solution:
Repeating fields are simply stored as additional rows with the same key for the field slug and their own value, so you can simply use update_post_meta to insert new rows.
I'm sure you understand updating post meta, and you must have looked in the wp_postmeta table and seen that repeating fields are simply additional rows with the same key for the field slug with their own value (see screenshot).
Is your question about targeting specific rows, e.g. if there are 4 repetitions of a field and you want to update the value of a particular one?
I basically want to add a value to the repeating field `wpcf-unlocked-ids` using PHP. I don't care what values are there, I don't need to change any of them or remove any of them, just want to add one to the end.
from what I see here, update post meta will change an existing entry but I need to add entries to the end of that list.
what I was looking for was add_post_meta.
I guess you just add another meta value on top of it and keep going... Wasn't expecting it to be this easy.
The solution is:
add_post_meta( $target_post_ID, 'wpcf-unlocked-ids', $the_id_i_want_to_add );
//$target_post_ID - the ID of the post that has the repeating field
//$the_id_i_want_to_add - the ID of the post I want to reference in here.
Thank you Nigel for pointing me in the right direction.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.