I have a form (form id 3) embedded on a single post page and I am wanting it, once submitted, to publish the post that was just submitted and then change the post status of the single post that I am on to 'draft'.
This works perfectly except that also I have 2 other forms on the site and the code below is targeting another form. So when the other form is submitted on it's page it is also changing the status of the page it is on to 'draft'.
I only want to change the status to draft when I am using form number 3. What have I done wrong??
// Action to change post status of project to draft after being selected
add_action("gform_after_submission", "set_post_content", 10, 2);
function set_post_content($form){
//only for form id
if($form["id"] == 3)
return $form;
//getting post
$post = get_post($post->ID);
//changing post content
$post->post_status = "draft";
//updating post
wp_update_post($post);
}