我正在尝试更改保存在post meta中的关联数组的特定键的值。以下是我的数组保存在自定义字段中的方式:
Array (
[0] => Array (
[321] => Zedity is an innovative content Editor to create posts or pages
)
[1] => Array (
[310] => A shortcode that includes other posts
)
)
以下是我尝试更新键321的值的方式:global $post;
$postid = $post->ID;
$add_to_ID = $_POST[\'wpd_plugin_note_id\'];
$note = $_POST[\'wpd_plugin_note\'];
$existing_list = get_post_meta($postid, \'my_list_items\', TRUE );
foreach ($existing_list as $key => $value) {
$existing_list[$key][$add_to_ID] = $note;
}
update_post_meta($postid,\'my_list_items\',$existing_list);
它可以工作,但在更新之后,数组如下所示,不是更新键321的值,而是将键=值对添加2次:Array (
[0] => Array (
[321] => my new value for 321
)
[1] => Array (
[310] => A shortcode that includes other posts
[321] => my new value for 321
)
)
有人能告诉我我做错了什么吗?谢谢