如何在wordpress帖子编辑中使用post_title值自动填充custom_field?

时间:2017-03-16 15:44:19

标签: php wordpress plugins

我需要发布帖子,在custom_field中插入一个值,同样的post_title值!

function add_custom_field_automatically_two($post_ID) {
global $post;
$post_id = $post->ID;
global $wpdb;
//$my_customf = $post->post_title;
//$my_customf = get_the_title( $post_id );
$my_customf = "something string"; // worked, but I need post_title!       
add_post_meta($post_ID, 'my_customf', $my_customf, true);
}
add_action('publish_page', 'add_custom_field_automatically_two');
add_action('publish_post', 'add_custom_field_automatically_two');
?>


Thanks.

0 个答案:

没有答案