-
-
Save prionkor/5207a953fbc9590acf104431f74719e2 to your computer and use it in GitHub Desktop.
caregory thumbnail plugin fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** ================================================== | |
* Update thumbnail meta data of a post to category thumbnail. | |
* Only updates if post doesn't have a thumbnail image set by user. | |
* | |
* @param int $post_id post_id. | |
* @since 2.00 | |
*/ | |
public function update_thumbnail( $post_id ) { | |
// Skip if current theme doesn't support post thumbnails | |
if ( ! current_theme_supports( 'post-thumbnails' ) ) { | |
return; | |
} | |
// Skip post thumbnail update if thumbnail is already set in the post | |
if ( has_post_thumbnail( $post_id ) ) { | |
return; | |
} | |
$term_id = $this->choose_term( $post_id ); | |
if ( 0 < $term_id ) { | |
$featured_image_id = intval( get_term_meta( $term_id, 'featured_image_id', true ) ); | |
update_post_meta( $post_id, '_thumbnail_id', $featured_image_id ); | |
} else { | |
delete_post_meta( $post_id, '_thumbnail_id' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment