Get single_image field value outside of loop

Support General Get single_image field value outside of loopResolved

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #21501
    rubbergumballrubbergumball
    Participant

    Similar question as at "Possible to retrieve custom field value of specific page outside loop?"

    I would like to add an OG: image file to the header of a specific CPT.

    Current header file code includes the following:

    $postID = get_queried_object_id();  
    $image = get_post_meta( $postID, 'my_img_id', true );
    //also tried these:
        //A  - $image = rwmb_meta( 'my_img_id', '', $postID );
        //B - /*foreach ( $image as $image_id ) {
              $image = RWMB_Image_Field::file_info( $image_id, array( 'size' => 'full' ) ); }*/
    echo "<meta property=\"og:image\" content=\"" . $image[url] . "\" />";

    The data is not populating the variable $image[url] - the field type is simple_image.

    Any thoughts?

    #21506
    Long NguyenLong Nguyen
    Moderator

    Hi Rubber,

    To get the element URL of the array which is returned by the helper function, please use it inside the single quote $image['url'].

    Please check the documentation https://docs.metabox.io/fields/single-image/#template-usage.

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