1

Is there a way to check the Published status of a post, and if it doesnt has at least one image or file uploaded, then change status of published to draft?

Thanks in advance.

1 Answer 1

1

I didn't test this, but it should work:

function check_post_attachments($post_id, $post){
  if(empty(get_posts(array('post_type' => 'attachment', 'post_parent' => $post_id)))){
     $post['post_status'] = 'draft';
     wp_update_post($post);
  }
}

add_action('save_post', 'check_post_attachments');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.