H
H
hypero2018-09-10 15:28:53
WordPress
hypero, 2018-09-10 15:28:53

Update post date after comment?

Hello.
I would like to do such a thing. So that when writing a comment to a post, the date of the post changes.
Are there any solutions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2018-09-10
@hypero

There is a comment_post hook. Cling to it and update the post https://wp-kama.ru/hook/comment_post

add_action( 'comment_post', 'update_post_date', 10, 2 );
function update_post_date( $comment_ID, $comment_approved ){

  $comment = get_comment( $comment_ID );
  $post = get_post( $comment->comment_post_ID );
  
      // Update the post  
        $my_post = array(  
            'ID'            => $post->ID,  
            'post_date'     => date("Y-m-d H:i:s"),  
            'post_date_gmt'     => date("Y-m-d H:i:s")  
        );  
      
        // Update the post into the database  
        wp_update_post( $my_post );  
}

Something like this...
corrected in functions.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question