Image in Group

Support MB Custom Post Type Image in Group

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #14358
    William JeromeWilliam Jerome
    Participant

    I am working through getting to know the plugin.

    It is possible to put single image into group? I tried the Group tutorial sample and got no result

    Here is the sample I modified.

    <?php
    $product_colour = rwmb_meta( 'product-colour' ); // ID of the group
    if ( ! empty( $product_colour ) ) {
        echo '<h3>', $product_colour['title'], '</h3>';
        echo '<h3>', $product_colour['image'], '</h3>';
    } ?>

    Also I am getting Undefined index: title error and not sure what that mean?

    Anyone know how to group image and text?

    #14376
    Anh TranAnh Tran
    Keymaster

    Hi William,

    It's necessary to check if a group has sub-values for title and image. Please try this code:

    <?php
    $product_colour = rwmb_meta( 'product-colour' ); // ID of the group
    if ( ! empty( $product_colour ) ) {
        if ( ! empty( $product_colour['title'] ) ) {
            echo '<h3>', $product_colour['title'], '</h3>';
        }
        if ( ! empty( $product_colour['image'] ) ) {
            $image = RWMB_Image_Field::file_info( $product_colour['image'], ['size' => 'thumbnail'] );
            echo '<img src="', $image['url'], '">';
        }
    }
    ?>
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.