Login Register

Login Here



  • Remove from your library.

Easily add, edit, remove post or user meta array elements

Easy method to manage post and user meta arrays. Add, edit, or remove post and user meta array elements.


This code makes an easy method for adding, editing and removing array elements in your post/user meta arrays. Examples:

  • $reval = update_meta_array(‘my_custom_meta’, array(“one”,”two”,”three”), “user”, “”, “new”, array(), true);
  • $reval = update_meta_array(‘my_custom_meta’, array(‘two’), “user”, “”, “remove”, array(“one”,”three”), true, $current_user->ID);

update_meta_assoc works the same way, just provide associative values instead of ‘flat’ ones. These methods do not support nested arrays or multidimensional arrays. If you are updating type “post”, then supply the fourth parameter (post id). If you are updating type “user”, then you can leave the last parameter blank and current user id will be used, or you can supply the user id. If an array is not returned, then a string value will be returned notifying you of the errors caught.

I'm a wordpress developer. I am admin of this site and hope everyone finds something of use for their own projects or learning.

0 comments on “Easily add, edit, remove post or user meta array elements

Join Discussion

Recent Discussions