Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * IF NO POST THUMB IS SET ON POST (EVENEMANG) SAVE, USE TAXONOMY IMAGE (requires taxonomy-images plugin)
- *
- */
- function check_for_taxonomy_images_plugin() {
- if(is_plugin_active('taxonomy-images/taxonomy-images.php')) {
- add_action('save_post', 'set_post_thumb', 10, 2);
- }
- }
- add_action('admin_init', 'check_for_taxonomy_images_plugin' );
- function set_post_thumb($post_id) {
- $event_type_id = 0;
- if(!wp_is_post_revision($post_id)) {
- $post_type = get_post_type($post_id);
- $post_thumb = get_post_thumbnail_id($post_id);
- if($post_type == 'evenemang' && !$post_thumb) {
- $event_types = get_the_terms($post_id, 'evenemangstyp'); // get terms associated with the post
- //$event_type_id = $event_types[0]->term_id; // get id of the first returned term
- $event_type_id = $event_types[0]->term_taxonomy_id;
- $tax_images = get_option('taxonomy_image_plugin'); // get TIP options
- if(!empty($tax_images)) {
- $defaultimage = $tax_images[$event_type_id];
- set_post_thumbnail($post_id,$defaultimage);
- }
- } // end $post_type === 'evenemang'
- }
- }
Add Comment
Please, Sign In to add comment