我阅读了另一个问题,并尝试了粘贴在下面的代码-Update post date on every new comment?
这段代码运行良好,但它会更新人们在前端插入注释的时间。我寻求的是更新管理员在后端批准评论的时间。
我读了另一个问题,试图用建议的钩子替换,但没有成功-Approve comment hook?
add_action(\'wp_insert_comment\',\'update_post_time\',99,2);
function update_post_time($comment_id, $comment_object) {
// Get the post\'s ID
$post_id = $comment_object->comment_post_ID;
// Double check for post\'s ID, since this value is mandatory in wp_update_post()
if ($post_id) {
// Get the current time
$time = current_time(\'mysql\');
// Form an array of data to be updated
$post_data = array(
\'ID\' => $post_id,
\'post_modified\' => $time,
\'post_modified_gmt\' => get_gmt_from_date( $time )
);
// Update the post
wp_update_post( $post_data );
}
}