Custom Fields
Re-Envisioned
Support General Get Image Src (URL) from Text Field and Set Featured Image

  • Creator
    Topic
  • #30920
    mrskt
    Participant

    Hi,

    Is it possible to get image source from Meta Box Custom text field and set it to featured image by using post_thumbnail_html.

    And image url in that field can be both External or Internal (Media Library) Src.

    My Custom Field id is: app_img_link

    Here is the few related topics links that can define my queries:
    https://wordpress.stackexchange.com/a/158568/210558

    https://wordpress.stackexchange.com/a/342159/210558

    But i want to get image src value from meta box custom field, Is there any snippets codes to solve my problem?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #30929
    Long Nguyen
    Moderator

    Hi,

    If you follow those topics to set the featured image based on the image URL, you can use the helper function rwmb_meta() to get the Meta Box field value.

    $value = rwmb_meta( 'app_img_link' );
    

    Please read more on the documentation https://docs.metabox.io/fields/text/#template-usage

    #30932
    mrskt
    Participant

    @longnguyen My Half Problem is solved, Can you tell how can i write below conditional tags in Twig:

    
    if( is_singular( $post_types = 'app' ) && $mimage = rwmb_meta( 'app_img_link' ) ) {
    
    [mbv name="apps-thumb"]
    
    }
    
    #30943
    Long Nguyen
    Moderator

    Hi,

    It just likes the code in the topic on WordPress.org forum https://wordpress.org/support/topic/how-to-write-php-code-in-twig/

    {% if( mb.is_singular( 'app' ) and mb.rwmb_meta( 'app_img_link' ) == 'your-img-link' %}
        [mbv name="apps-thumb"]
    {% endif %}
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.