Can't get image to output
Support › MB Term Meta › Can't get image to output
- This topic has 3 replies, 2 voices, and was last updated 7 years, 5 months ago by
chimovski.
Viewing 4 posts - 1 through 4 (of 4 total)
-
AuthorPosts
-
November 19, 2017 at 12:16 AM #7447
chimovski
Participant//Add metaboxes to Sector taxonomy /////////////////////////////////////////////////////// add_filter( 'rwmb_meta_boxes', 'prefix_register_taxonomy_meta_boxes' ); function prefix_register_taxonomy_meta_boxes( $meta_boxes ){ $meta_boxes[] = array( 'title' => 'Extra info', 'taxonomies' => 'base_sector', // List of taxonomies. Array or string 'fields' => array( // featured image array( 'name' => 'Featured Image', 'id' => 'tax_img', 'type' => 'image_advanced', ), ), ); return $meta_boxes; }
In my template I'm trying to output the image but can't figure out how to do it.
<?php // Get Sectors $post_type = 'base_project'; // Get all the taxonomies for this post type $taxonomies = get_object_taxonomies( array( 'post_type' => $post_type ) ); foreach( $taxonomies as $taxonomy ) : // Gets every term in this taxonomy $terms = get_terms( $taxonomy ); foreach( $terms as $term ) : echo "<div class='grid-item'><div class='pic sector'>"; $images = get_term_meta( $term->term_id, 'image_advanced', false ); if ( $tax_images ) { foreach ( $tax_images as $tax_image ) { $tax_image = RWMB_Image_Field::file_info( $tax_image, 'thumbnail' ); echo "<img src='{$tax_image['url']}' alt='{$tax_image['alt']}' />"; } } ?>
November 19, 2017 at 6:41 PM #7451chimovski
Participanttaking from the example in the documentation
// Getting images $image_ids = get_term_meta( $term_id, $field_id, false ); // Media fields are always multiple. foreach ( $image_ids as $image_id ) { $image = RWMB_Image_Field::file_info( $image_id, array( 'size' => 'thumbnail' ) ); echo '<img src="' . $image['url'] . '">'; }
I've setup the metaboxes like this
add_filter( 'rwmb_meta_boxes', 'prefix_register_taxonomy_meta_boxes' ); function prefix_register_taxonomy_meta_boxes( $meta_boxes ){ $meta_boxes[] = array( 'title' => 'Extra info', 'taxonomies' => 'base_sector', // List of taxonomies. Array or string 'fields' => array( // featured image array( 'name' => 'Featured Image', 'id' => 'tax_img', 'type' => 'image_advanced', ), ), ); return $meta_boxes; }
I've been playing around with it for hours and can't get it to work.
November 20, 2017 at 8:34 AM #7455Truong Giang
ParticipantHi there,
Can you usevar_dump( $image_ids )
and give me the output?Thanks.
November 20, 2017 at 8:48 PM #7459chimovski
ParticipantManaged to sort it. I wasn't query the terms properly.
<?php $custom_terms = get_terms('base_sector'); foreach($custom_terms as $custom_term) { $term_id = $custom_term->term_id; $image_ids = get_term_meta( $term_id, 'tax_img', false ); foreach ( $image_ids as $image_id ) { $image = RWMB_Image_Field::file_info( $image_id, array( 'size' => 'thumbnail' ) ); echo "<img src='{$image['url']}' alt='{$image['alt']}' />"; } } ?>
-
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
- The topic ‘Can't get image to output’ is closed to new replies.