Taxonomy Image on Custom Post Type
Support › MB Term Meta › Taxonomy Image on Custom Post TypeResolved
- This topic has 2 replies, 2 voices, and was last updated 3 years, 1 month ago by
Ole Poetter.
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
March 21, 2022 at 7:33 PM #35179
Ole Poetter
ParticipantHi,
regarding to this topic https://support.metabox.io/topic/taxonomy-image-on-custom-post-type/ I try to display in Image field of a custom term on the post display.
I try to make a shordcode like this:
function custom_shortcode() { $terms = get_the_terms( get_queried_object_id(), 'language' ); foreach ( $terms as $term ) { $term_image = rwmb_meta( 'term_flag', ['object_type' => 'term'], $term->term_id ); if( is_array( $term_image ) ) { echo '<img src="'. $term_image['full_url'] .'">'; echo '<pre>'; // just for debugging var_dump($term_image); // just for debugging echo '</pre>'; // just for debugging } } } add_shortcode( 'termimage', 'custom_shortcode' );
I get an php warning:
Undefined array key "full_url"
This is the output of the var_dump:
array(1) { [385]=> array(15) { ["width"]=> int(40) ["height"]=> int(24) ["file"]=> string(15) "2022/03/de1.png" ["sizes"]=> array(0) { } ["image_meta"]=> array(12) { ["aperture"]=> string(1) "0" ["credit"]=> string(0) "" ["camera"]=> string(0) "" ["caption"]=> string(0) "" ["created_timestamp"]=> string(1) "0" ["copyright"]=> string(0) "" ["focal_length"]=> string(1) "0" ["iso"]=> string(1) "0" ["shutter_speed"]=> string(1) "0" ["title"]=> string(0) "" ["orientation"]=> string(1) "0" ["keywords"]=> array(0) { } } ["ID"]=> string(3) "385" ["name"]=> string(7) "de1.png" ["path"]=> string(111) "/var/www/vhosts/t36updxb.web5.alfahosting-server.de/mylistingshowcase.online/wp-content/uploads/2022/03/de1.png" ["url"]=> string(67) "https://mylistingshowcase.online/wp-content/uploads/2022/03/de1.png" ["full_url"]=> string(67) "https://mylistingshowcase.online/wp-content/uploads/2022/03/de1.png" ["title"]=> string(5) "de[1]" ["caption"]=> string(0) "" ["description"]=> string(0) "" ["alt"]=> string(0) "" ["srcset"]=> bool(false) } }
Can you please assist and tell me where is my mistake?
I'm a non professionell developer.Thank you!
March 22, 2022 at 5:40 PM #35199Long Nguyen
ModeratorHi Ole,
That means you need to use a second
for
loop to iterate through$term_image
array to get images$term_image = rwmb_meta( 'term_flag', ['object_type' => 'term'], $term->term_id ); if( is_array( $term_image ) ) { foreach ( $term_image as $image ) { echo '<img src="'. $image['full_url'] .'">'; } }
March 22, 2022 at 5:42 PM #35200Ole Poetter
ParticipantHi Long,
I thank you so much!
I have to learn a lot more 😉 -
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.