您需要使用save_post_post
挂钩和使用$wpdb->update()
方法代码-
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="%s">%s</a>\',
$rpost->post_title,
get_permalink( $rpost->ID )
);
}
}
$wpdb->update(
$wpdb->posts,
array( \'post_content\' => $post_content ),
array( \'ID\' => $post_ID )
);
}