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

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

1 Answer 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';

add_action('save_post', 'check_post_attachments');
share|improve this answer

Your Answer


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.