Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I using post meta like..

$meta = get_post_meta(99,'_mymeta',true);
$value = $meta['somekey'];
echo $value;

But how to update $meta['somekey'] to some another value ?

How to use update_post_meta to update sub meta key ?(Idk, How ppl call)

update_post_meta(99, '_mymeta["somekey"]', 'myAnotherValue');

?????

share|improve this question

1 Answer 1

up vote 3 down vote accepted

To update post meta that are an array: you have to fetch the original values, change the value you need and update it again. For example

$list_of_values = get_post_meta($post_id, '_list_values', true);
if(!empty($list_of_values)) {
    $list_of_values["some_prop"] = "new value";
}
update_post_meta($post_id, '_list_values', $list_of_values);
share|improve this answer
    
Thanks so much , What about deleting an array ? –  l2aelba May 14 '13 at 8:58
2  
@l2aelba: you can either set the value to empty, or do unset($list_of_values["element_to_delete"]); –  Angela May 14 '13 at 9:05
    
thanks so much @Angela –  l2aelba May 14 '13 at 9:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.