Update post “A” on comment submition on post “B”

Question

Hello and thanks in advance for any help. Im trying to update the post status from a post when submiting a comment on other post, I have a variable in the url pointing to the ID of the post I want to update like so mysite.com/some-post/?id=1234

Hooking into ‘comment_post’ wont get the variable, so a new post is created insted of updating

add_action( 'comment_post', 'aa_comment_update_post' );

function aa_comment_update_post( $comment_ID ) {

   $id = $_GET['id'];

   $postarr = array(
      'ID'            => $id,
      'post_status'   => 'draft',
   );

  wp_update_post( $postarr );

}

Any idea would be much appreciated

0
, , A. Hartzet 1 year 2020-07-22T18:10:30-05:00 0 Answers 55 views 0

Leave an answer

Browse
Browse