我在WordPrss中有这个save_post
操作钩子。
function save_meta_function ( ) {
global $post;
$post_id = $post->ID;
$meta_values = get_post_meta( $post_id );
// echo '<pre>';
// print_r($meta_values);
// echo '</pre>';
foreach ($meta_values as $key => $value) {
//print_r($key);
//print_r($value[0]);
// $newValue = $value[0];
update_post_meta( $post_id, $key, $value[0] );
}
}
add_action( 'save_post', 'save_meta_function' );
此评论行:
// echo '<pre>';
// print_r($meta_values);
// echo '</pre>';
将打印以下内容:
<pre>Array
(
[people_0] => Array
(
[0] => 2
)
[people_1] => Array
(
[0] => two@gmail.com
)
[people_2] => Array
(
[0] => Author Two
)
[people_3] => Array
(
[0] => Author Aff 2
)
[people_4] => Array
(
[0] => #2- Article 2 Title
)
[people_5] => Array
(
[0] => Article 2 URL
)
[people_6] => Array
(
[0] => Article 2 Journal
)
[people_7] => Array
(
[0] => Article 2 Abstract
)
[people_8] => Array
(
[0] => Co Author 2
)
[people_9] => Array
(
[0] => Co Author Aff 2
)
[people_10] => Array
(
[0] => co-author-2@gmail.com
)
[people_11] => Array
(
[0] => Article 2 Title
)
[people_12] => Array
(
[0] => Article 2 URL
)
[people_13] => Array
(
[0] => Article 2 Journal
)
[people_14] => Array
(
[0] => Article 2 Abstract
)
[people_15] => Array
(
[0] => Co Author 2
)
[people_16] => Array
(
[0] => Co Author Aff 2
)
[people_17] => Array
(
[0] => co-author-2@gmail.com
)
[_edit_lock] => Array
(
[0] => 1562141363:1
)
[_edit_last] => Array
(
[0] => 1
)
)
现在,当我编辑或添加新数据时,由于某种原因update_post_meta()
方法未更新后的meta :(您能告诉我为什么吗?