3

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');

?????

1 Answer 1

5

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);
2
  • Thanks so much , What about deleting an array ? Commented May 14, 2013 at 8:58
  • 2
    @l2aelba: you can either set the value to empty, or do unset($list_of_values["element_to_delete"]); Commented May 14, 2013 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.