How Can I add Image Custom Field URLs to RSS Feed?

Support MB Builder How Can I add Image Custom Field URLs to RSS Feed?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #46127
    Adam ZahlerAdam Zahler
    Participant

    Hi,

    I have a custom post type with a number of custom fields, including some image fields. I have created a custom RSS feed for the CPT and I would like to include the images within the RSS feed. I've tried Advanced Images, Single Images, etc but I don't know how to get the images to show in the feed. The best I have got is the image ID to show.

    The code snippet I am using for one of the image custom fields is is as follows:

    add_action('rss2_item', 'add_custom_field5_to_rss');
    function add_custom_field5_to_rss() {
        if(get_post_type() == 'holiday-home' && $my_meta_value5 = get_post_meta(get_the_ID(), 'holiday_home_image_03', true)) {
            ?>
            <holidayhomecustomfields:holiday_home_image_01><?php echo $my_meta_value5 ?></holidayhomecustomfields:holiday_home_image_03>
            <?php
        }
    }

    I'm assuming I need to get the image URLs to show in the feed instead of the image IDs so can anyone tell me how to modify the code above so the image URL is returned?

    Really appreciate any help!

    Adam

    #46137
    PeterPeter
    Moderator

    Hello Adam,

    You can use the helper function rwmb_meta() to get the full image info. Please follow the documentation
    https://docs.metabox.io/fields/single-image/#template-usage

    $my_meta_value5 = rwmb_meta( 'single_image_id', ['size' => 'thumbnail'], get_the_ID() );
    echo $my_meta_value5['url'];
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.