You need to use save_post_post
hook and use $wpdb->update()
method. The code –
add_action( 'my_save_post_post', 'save_post_post' );
function my_save_post_($post_ID, $post )
{
global $wpdb;
$post_content="You are viewing ". $post->post_title .'! These are great hairstyle designs in our '. get_the_category_list( ', ', '', $post_ID ) .' section. Hope you try this look and feel on your hair today. Ever considered changing it up, you might like this';
$random = get_posts( array(
'post__not_in' => $post_ID,
'posts_per_page' => '1',
'post_type' => 'post',
'post_status' => 'publish',
'orderby' => 'rand'
));
if( $random )
{
$rpost = array_shift( $random );
if( isset($rpost->ID) )
{
$post_content .= sprintf(
' <a href="https://wordpress.stackexchange.com/questions/129314/%s">%s</a>',
$rpost->post_title,
get_permalink( $rpost->ID )
);
}
}
$wpdb->update(
$wpdb->posts,
array( 'post_content' => $post_content ),
array( 'ID' => $post_ID )
);
}