Custom Fields
Re-Envisioned
Support Meta Box Builder Retrieving Single Image URL in Oxygen Builder

  • Creator
    Topic
  • #23976
    Resolved Bret Carmichael
    Participant

    Hi there,

    I am using Oxygen and am trying to display a single_image that uploaded to a post.

    I created a function with the hope that it would output the image's URL, but it doesn't return anything.

    function mb_cp_logo_shortcode() {
    $image = rwmb_meta( 'info', array( 'size' => 'full' ) );
    echo '<a href="', $image['full_url'], '"><img src="', $image['url'], '"></a>';
    }
    add_shortcode( 'mb-cp-logo', 'mb_cp_logo_shortcode' );
    

    I based the function off of this page, https://docs.metabox.io/fields/single-image/, but I clearly didn't implement it correctly.

    I did a search before posting. I found the below topic, but it didn't get me where I needed.

    https://metabox.io/support/topic/retrieving-image-in-post-from-new-field/

    Thanks!

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #23979
    Long Nguyen
    Moderator

    Hi Bret,

    There are two points you need to notice:

    function mb_cp_logo_shortcode() {
        $image = rwmb_meta( 'info', array( 'size' => 'full' ) );
        return '<a href="'. $image['full_url']. '"><img src="'. $image['url']. '"></a>';
    }
    add_shortcode( 'mb-cp-logo', 'mb_cp_logo_shortcode' );
    • If you add the shortcode when editing the post with the Oxygen Builder, you don't need to pass the third-argument $post_id to the shortcode. But if you add the shortcode to the Grid Builder of Oxygen and insert the Grid when editing the post, you have to pass the post ID to the shortcode.
    function mb_cp_logo_shortcode() {
        $image = rwmb_meta( 'info', array( 'size' => 'full' ), 123 );
        return '<a href="'. $image['full_url']. '"><img src="'. $image['url']. '"></a>';
    }
    add_shortcode( 'mb-cp-logo', 'mb_cp_logo_shortcode' );

    See more in the documentation https://docs.metabox.io/rwmb-meta/#arguments.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.