[英]Automatically appending post title into post content upon publishing of post?
Please tell me, how can I fetch the post title and append it into the content of that post when I click the publish button? 请告诉我,当我单击发布按钮时,如何获取帖子标题并将其附加到该帖子的内容中?
Thank you! 谢谢!
The wp_insert_post_data
filter allows you to manipulate the post data before it is inserted in the database: wp_insert_post_data
过滤器允许您在将帖子数据插入数据库之前对其进行操作:
function so16876611_insert_post_data( $data , $postarr )
{
$data['post_content'] = $data['post_content'] . $data['post_title'];
return $data;
}
add_filter( 'wp_insert_post_data', 'so16876611_insert_post_data', 99, 2 );
You would need to access save_post hook that's being triggered after creating/updating page. 您需要访问在创建/更新页面后触发的save_post挂钩。 It would look something like below:
如下所示:
function custom_save_post($post_id)
{
$_POST['content']= $_POST['post_name'].$_POST['content'];
}
add_action("save_post", "custom_save_post");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.