$echo = false does not work for rwmb_the_value, getting url of advanced image fi

Support General $echo = false does not work for rwmb_the_value, getting url of advanced image fiResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #32394
    Lanzelot MollLanzelot Moll
    Participant

    Hey,
    i am trying to do something like this in a loop:

    (I removed the < >, so it is not displayed as an image here)

    $query = new WP_Query( array( 'post_type' => 'bild' ) );
    in the Loop:
      $bild = rwmb_the_value($field_id = "url_", $echo =false);
      echo 'img src="', $bild, '" /';'

    I have two questions. First of all $echo = false does not work for me.
    Everytime the Url is output into the HTML instead of just being returned to the variable.
    How can I fix this?

    Apart from the echo issue the first version is working, but i would prefer to use rwmb_the_value/rwmb_meta to get the url of a image that is selected by the advanced image field. So I my client can choose an image directly instead of having to search for the url. So to say:

    $image = rwmb_the_value(or rmwb_meta?)( $field_id = 'field_id', array( 'size' => 'original' ), $echo = false)
    echo 'img src="', $bild['url'], '" /';

    I found something with rmwb_meta in the single image documentation but it did not work.
    Can you provide me with the correct syntax please? And tell me how to resolve the echo issue?

    Special thanks in advance

    #32401
    Lanzelot MollLanzelot Moll
    Participant

    Also i don't understand this:

    echo '<p>', rwmb_the_value($field_id = "textarea_"), '</p>';

    why does this output the text of the textarea twice? Again here, $echo = false does not work

    #32402
    Lanzelot MollLanzelot Moll
    Participant

    So in the end I tried to use the shortcodes instead and the problem vanished. Everything is just displayed once. The documentation says that the shortcode and the the_value function do the exact same thing? In my case they definitely did not!

    do_shortcode( ' [rwmb_meta id="bild" attribute="url" size="large"] '

    by looking for shortcodes, I also came across the solution for my url problem

    #32429
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You just need to run the helper function rwmb_the_value() to print out the field value without using echo. Please refer to this topic https://support.metabox.io/topic/why-does-echo-rwmb_the_value-display-a-value-twice/

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