EDIT: Original answer was inaccurate as you can do this with wp_update_post and the meta_input
field
As per the updated question and comments this is possible with wp_update_post
(or wp_insert_post
for a new record) using the meta_input
key on the array, e.g.:
$metaValues = array(
'key1' => 'value1',
'key2' => 'value2',
// ... as many key/values as you want
);
wp_update_post(array(
'ID' => $postId,
'meta_input'=> $metaValues,
));
Original Answer (Works but no point doing it like this given above option)
Nope. The docs clearly show the function doesn’t support that.
Obviously you can use an array to pass through many values if you have a bunch of things to do at the same time.
This is a PHP programming question, not a WordPress question, but the code would look something like this:
$postId = 1234;
// Perhaps you have multiple key value pairs, like this:
$metaValues = array(
'key1' => 'value1',
'key2' => 'value2',
// ... as many key/values as you want
);
// Set all key/value pairs in $metaValues
foreach ($metaValues as $metaKey => $metaValue) {
update_post_meta($postId, $metaKey, $metaValue);
}
Or this just to update the value on many keys:
// Or maybe you want to update a bunch of keys with the same value for some reason..
$metaValue = "10";
$metaKeys = Array("key1", "key2"); // as many keys as you want here
foreach($metaKeys as $metaKey) {
update_post_meta($postId, $metaKey, $metaValue);
}