Created
February 28, 2022 06:32
-
-
Save AchalJ/fb74303ceccec49826596b3e4ebca94a to your computer and use it in GitHub Desktop.
PowerPack Content Grid - Display taxonomy term thumbnail in post as a fallback image
This file contains hidden or 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
| add_filter( 'pp_post_image_settings_data', function( $data, $settings ) { | |
| global $post; | |
| if ( false !== strpos( $data['photo_src'], 'placeholder.jpg' ) ) { | |
| $terms = get_the_terms( $post->ID, 'category' ); // Here "category" is the post taxonomy slug. | |
| if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) { | |
| $term = $terms[0]; | |
| $term_thumb_id = get_term_meta( $term->term_id, 'taxonomy_thumbnail_id', true ); | |
| if ( '' !== $term_thumb_id ) { | |
| $obj_term_thumb = wp_get_attachment_image_src( $term_thumb_id, 'medium' ); | |
| $data['photo_src'] = $obj_term_thumb[0]; | |
| } | |
| } | |
| } | |
| return $data; | |
| }, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment