Output image advanced in a function (Oxygen builder)

Support Meta Box AIO Output image advanced in a function (Oxygen builder)

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #35415
    Care DigitalCare Digital
    Participant

    Hi,
    I was trying to use repeater to query data and wanted to output the image using php function return value option for dynamic data in Oxygen. However, with my lack of knowledge in php, I have no idea how to achieve that. (I want to use image advanced since I'll have a lot of pictures)

    So I came up with the following code;
    function my_get_mb_advanced_image($field) {
    $term_id = get_queried_object_id();
    $images = rwmb_the_value( $field, array( 'size' => 'thumbnail' ) );
    foreach ( $images as $image ) {
    return $image['url'];
    }
    But I guess it was completely wrong since it could not display the image.
    So if anybody could help me on this, that'd be really awesome.
    Thanks!
    Nanan

    #35429
    Long NguyenLong Nguyen
    Moderator

    Hi,

    If you want to output the image of the term meta, you can try to use this code

    $term_id = get_queried_object_id();
    $images = rwmb_meta( $field_id, ['object_type' => 'term', 'size' => 'thumbnail'], $term_id );
    foreach ( $images as $image ) {
    ...
    }

    Refer to the documentation
    https://docs.metabox.io/extensions/mb-term-meta/#getting-field-value
    https://docs.metabox.io/fields/image-advanced/#template-usage

    #35435
    Care DigitalCare Digital
    Participant

    Hi Long,
    Thank you very much for your reply.
    Would it be possible to change the output you provided to the function for me please? as I'd like to use the function return php in this case if possible.

    Much appreciated.
    Nanan

    #35452
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can add the code above to your function to use in the builder. For example:

    function my_get_mb_advanced_image($field) {
    	$term_id = get_queried_object_id();
    	$images = rwmb_meta( $field_id, ['object_type' => 'term', 'size' => 'thumbnail'], $term_id );
    	foreach ( $images as $image ) {
    		echo '<a href="' .$image['full_url']. '"><img src="' .$image['url']. '"></a>';
    	}
    }

    For further info, please contact Oxygen support to ask for implementation of the code in the repeater.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.