lolitaloco

set post thumb (req. taxonomy-images plugin) (wordpress)

Apr 25th, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1.         /*
  2.          * IF NO POST THUMB IS SET ON POST (EVENEMANG) SAVE, USE TAXONOMY IMAGE (requires taxonomy-images plugin)
  3.          *
  4.          */      
  5.         function check_for_taxonomy_images_plugin() {
  6.             if(is_plugin_active('taxonomy-images/taxonomy-images.php')) {
  7.                 add_action('save_post', 'set_post_thumb', 10, 2);
  8.             }
  9.         }  
  10.         add_action('admin_init', 'check_for_taxonomy_images_plugin' );
  11.         function set_post_thumb($post_id) {
  12.             $event_type_id = 0;
  13.             if(!wp_is_post_revision($post_id)) {
  14.                 $post_type = get_post_type($post_id);
  15.                 $post_thumb = get_post_thumbnail_id($post_id);
  16.                 if($post_type == 'evenemang' && !$post_thumb) {            
  17.                      $event_types = get_the_terms($post_id, 'evenemangstyp'); // get terms associated with the post
  18.                      //$event_type_id = $event_types[0]->term_id; // get id of the first returned term
  19.                        $event_type_id = $event_types[0]->term_taxonomy_id;
  20.                          $tax_images = get_option('taxonomy_image_plugin'); // get TIP options
  21.                      if(!empty($tax_images)) {                     
  22.                         $defaultimage = $tax_images[$event_type_id];           
  23.                         set_post_thumbnail($post_id,$defaultimage);
  24.                     }          
  25.                 } // end $post_type === 'evenemang'
  26.             }  
  27.         }
Add Comment
Please, Sign In to add comment