Posted By

lolitaloco on 04/28/12


Tagged

wordpress postthumb


Versions (?)

Set post thumb to default if missing on post save


 / Published in: PHP
 

set post thumb if missing on post save

  1. function init_set_thumb() {
  2. add_action('save_post', 'set_post_thumb', 10);
  3. }
  4. add_action('admin_init', 'init_set_thumb');
  5.  
  6. function set_post_thumb($post_id) {
  7. if(!wp_is_post_revision($post_id)) {
  8. $post_type = get_post_type($post_id);
  9. $post_thumb = get_post_thumbnail_id($post_id);
  10. if($post_type == 'post' && !$post_thumb) { // if post type = post and get_post_thumbnail == false
  11. $defaultimage = 1; // set to id of attachment to use as default post thumb
  12. set_post_thumbnail($post_id,$defaultimage);
  13. }
  14. }
  15. }

Report this snippet  

You need to login to post a comment.