事实上,Wordpress提供了一个很好的挂钩,您可以从发布的帖子中获取数据,更多信息,请遵循以下示例:https://codex.wordpress.org/Plugin_API/Action_Reference/publish_post自定义字段的简单更新示例:
/* Do something with the data entered */
add_action( \'save_post\', \'myplugin_save_postdata\' );
/* When the post is saved, saves our custom data */
function myplugin_save_postdata( $post_id ) {
// First we need to check if the current user is authorised to do this action.
if ( \'page\' == $_POST[\'post_type\'] ) {
if ( ! current_user_can( \'edit_page\', $post_id ) )
return;
}
else {
if ( ! current_user_can( \'edit_post\', $post_id ) )
return;
}
$mydata = \'something\'; // Do something with $mydata
update_post_meta( $post_id, \'_my_meta_value_key\', $mydata );
}