Created
December 11, 2018 14:38
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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