Why does `echo rwmb_the_value` display a value twice?

Support General Why does `echo rwmb_the_value` display a value twice?Resolved

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #23997
    brandonjpbrandonjp
    Participant

    I'm trying to actually understand why using echo produces different results when displaying values. I have num_of_items stored with a value of 6.

    rwmb_THE_value:
    * THE: <dd><?php rwmb_the_value('num_of_items'); ?></dd> displays 6
    * ECHO THE: <dd><?php echo rwmb_the_value('num_of_items'); ?></dd> displays 66

    rwmb_GET_value:
    * GET: <dd><?php rwmb_get_value('num_of_items'); ?></dd> displays nothing
    * ECHO GET: <dd><?php echo rwmb_the_value('num_of_items'); ?></dd> displays 6

    I've been studying the related docs: https://docs.metabox.io/rwmb-get-value/ & https://docs.metabox.io/rwmb-the-value/ - But still a little confused on how/why echo affects them.

    #24005
    Long NguyenLong Nguyen
    Moderator

    Hi,

    For example:

    function yourStatus(){
       echo ' Done';
    }
    
    echo 'Status ='. yourStatus();

    your output will look like this

    "DoneStatus ="

    instead of

    "Status = Done"

    Echo in a function is to send a value to the output buffer and echo the function to send it's output to the output.

    There is an echo inside the helper function rwmb_the_value() so the value will print twice. See more in the source code: https://github.com/wpmetabox/meta-box/blob/master/inc/functions.php#L181-L208

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