WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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');
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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