Add recursive post meta function

This commit is contained in:
Brian Miyaji
2016-12-08 19:15:01 +11:00
parent 2f7c215ad9
commit f4d525b943

View File

@@ -1095,9 +1095,8 @@ if ( !function_exists( 'sp_update_post_meta' ) ) {
}
}
if ( !function_exists( 'sp_update_post_meta_recursive' ) ) {
function sp_update_post_meta_recursive( $post_id, $meta_key, $meta_value ) {
delete_post_meta( $post_id, $meta_key );
if ( !function_exists( 'sp_add_post_meta_recursive' ) ) {
function sp_add_post_meta_recursive( $post_id, $meta_key, $meta_value ) {
$values = new RecursiveIteratorIterator( new RecursiveArrayIterator( $meta_value ) );
foreach ( $values as $value ):
add_post_meta( $post_id, $meta_key, $value, false );
@@ -1105,6 +1104,13 @@ if ( !function_exists( 'sp_update_post_meta_recursive' ) ) {
}
}
if ( !function_exists( 'sp_update_post_meta_recursive' ) ) {
function sp_update_post_meta_recursive( $post_id, $meta_key, $meta_value ) {
delete_post_meta( $post_id, $meta_key );
sp_add_post_meta_recursive( $post_id, $meta_key, $meta_value );
}
}
if ( !function_exists( 'sp_update_user_meta_recursive' ) ) {
function sp_update_user_meta_recursive( $user_id, $meta_key, $meta_value ) {
delete_user_meta( $user_id, $meta_key );