• Resolved mschoenhardt

    (@mschoenhardt)


    I’ve got a set of key_value’s that I’d like to use to create buttons on the front end, allowing my client to place both a URL and the title of the button. Backend stuff works fine, but can’t figure out how to echo out the key_value, I just get arrays.

    Backend:

    array(
    'id' => 'links',
    'name' =>__('Extra Links','projects'),
    'desc' => 'Key is button title, value is the URL. Please include http://',
    'type' => 'key_value',
    ),

    Front end attempt, this just returns blank.:

    $links = rwmb_meta('links');
    if ( !empty ( $links ) ) {
    	foreach ( $links as $link ) {
    		echo "<a href='{$link['value']}' class='btn btn-primary btn-block' target='_blank'>{$link['key']}</a>";
    	} //end links if
    }

    Tried this to simplify & troubleshoot:

    foreach ( $links as $link ) {
    	echo $link;
    } //end links if

    Which just echos “Array Array”. Any suggestions? Thanks!

    • This topic was modified 8 years, 11 months ago by mschoenhardt.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Manny Fleurmond

    (@funkatronic)

    The key is stored as 0 and the value as 1, so:

    $links = rwmb_meta('links');
    if ( !empty ( $links ) ) {
    	foreach ( $links as $link ) {
    		echo "<a href='{$link[1]}' class='btn btn-primary btn-block' target='_blank'>{$link[0]}</a>";
    	} //end links if
    }
    Thread Starter mschoenhardt

    (@mschoenhardt)

    Worked like a charm, thank you so much!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Display key_value on front end’ is closed to new replies.