Skip to content

Instantly share code, notes, and snippets.

@KnightAlex
Created December 11, 2018 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KnightAlex/0c1ee83683e89642ef4ac3f8bcfb1fd6 to your computer and use it in GitHub Desktop.
Save KnightAlex/0c1ee83683e89642ef4ac3f8bcfb1fd6 to your computer and use it in GitHub Desktop.
Re-save comma separated list of values into a "multiple instances of this field" field. WPAI.
add_action( 'pmxi_saved_post', 'post_saved', 10, 1 );
function post_saved( $id ) {
$comma_values = get_post_meta($id, 'my_custom_field', true);
$explode_comma_values = explode( ',', $comma_values );
delete_post_meta( $id, 'my_custom_field', $comma_values ); //Clear custom field first
foreach($explode_comma_values as $v){
add_post_meta( $id, 'my_custom_field', $v );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment