Up to 50 percent off

Repeat field and wp insert post

This topic contains 1 reply and 2 voices, and was last updated by Tareq Hasan 11 years, 1 month ago
Viewing 1 Posts - 1 through 1 (of 1 total)
Author Posts
October 17, 2013 at 11:55 pm 9153
Tareq Hasan Hi I need a hint for saving repeat field values with wp_insert_post. I'm creating two different posts with one form and everything works good with wp_insert_post and wpuf_add_post_after_insert but I'm stucked with the repeat field. Maybe you have some other way around of creating two posts with one form...? thanks
October 18, 2013 at 9:47 pm 9188
Tareq Hasan Tareq Hasan

For multi-column repeat field, every row saves as a new meta field. Here’s the multicolumn code that the plugin uses:
[php]
// save any multicolumn repeatable fields
foreach ($multi_repeated as $repeat_key => $repeat_value) {
// first, delete any previous repeatable fields
delete_post_meta( $post_id, $repeat_key );

// now add them
foreach ($repeat_value as $repeat_field) {
add_post_meta( $post_id, $repeat_key, $repeat_field );
}
}
[/php]

For single column, it uses a separator (| – pipe) for every field and saves in a single meta key concatenated.

Viewing 1 Posts - 1 through 1 (of 1 total)