Get Image Src (URL) from Text Field and Set Featured Image

Support General Get Image Src (URL) from Text Field and Set Featured Image

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #30920
    mrsktmrskt
    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?

    #30929
    Long NguyenLong 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
    mrsktmrskt
    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 NguyenLong 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 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.