EDIT: Original answer was inaccurate as you can do this with wp_update_post and the meta_input
field
根据更新后的问题和评论,这可以通过
wp_update_post
(或
wp_insert_post
对于新记录),使用
meta_input
在阵列上键入,例如:
$metaValues = array(
\'key1\' => \'value1\',
\'key2\' => \'value2\',
// ... as many key/values as you want
);
wp_update_post(array(
\'ID\' => $postId,
\'meta_input\'=> $metaValues,
));
Original Answer (如上述选项所示,这样做是可行的,但没有意义)
没有。The docs 清楚地显示功能不支持这一点。
显然,如果您同时有许多事情要做,那么可以使用数组来传递许多值。
这是一个PHP编程问题,不是Wordpress问题,但代码如下所示:
$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 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);
}