0

I'm setting up two wordpress sites. I have a custom RSS Feed on my first site, and i want to display the custom field on my second site. It's the featured image.

I am able to display the standard fields "title" or "permalink" like this : "get_title(); ?>". But can not display the new field "image".

The custom RSS is :

<channel>
<title>TITRE CATEGORIE</title>
    <atom:link href="http://127.0.0.1/site/feed/" rel="self" type="application/rss+xml" />
    <link>http://127.0.0.1/site</link>
    <description>DESCRIPTION</description>
    <lastBuildDate>Fri, 05 Jul 2019 13:15:21 +0000</lastBuildDate>
    <language>fr-FR</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <generator>https://wordpress.org/?v=5.2.2</generator>
    <item>
        <title>TITRE</title>
        <link>http://127.0.0.1/site/page</link>
        <pubDate>Wed, 26 Jun 2019 15:56:57 +0000</pubDate>
        <dc:creator><![CDATA[gregory]]></dc:creator>
        <category><![CDATA[cat-1]]></category>
        <category><![CDATA[cat-2]]></category>
        <guid isPermaLink="false">http://127.0.0.1/site/?p=56</guid>
        <description><![CDATA[<p>L’article <a rel="nofollow" href="http://127.0.0.1/site/page/">Webserie 1</a> est apparu en premier sur <a rel="nofollow" href="http://127.0.0.1/site">NOM DU SITE</a>.</p>
]]></description>
        <content:encoded><![CDATA[<p>L’article <a rel="nofollow" href="http://127.0.0.1/site/page/">TITRE</a> est apparu en premier sur <a rel="nofollow" href="http://127.0.0.1/site">NOM DU SITE</a>.</p>
]]></content:encoded>
        <image><![CDATA[http://127.0.0.1/site/wp-content/uploads/2019/07/cookies.jpg]]></image>
    </item>

I use this code to display the rss :

<?php if(function_exists('fetch_feed')) {
    include_once(ABSPATH . WPINC . '/feed.php');
    $feed = fetch_feed('http://127.0.0.1/site/tag/musique/feed/');
    $limit = $feed->get_item_quantity(1);
    $items = $feed->get_items(0, $limit);
} ?>

    <?php foreach ($items as $item) : ?>

        <?php echo $item->get_title(); ?>
        <?php echo $item->get_permalink(); ?>
        <?php echo $item->image; ?>

    <?php endforeach; ?>

The field "image" display nothing... How to target this line of the items ? Thanks for your help \o/

Marouy
  • 1
  • 1

1 Answers1

0

You'd want to get the featured image, so something like:

get_the_post_thumbnail('thumbnail');

to add to your code:

<?php echo $item->get_the_post_thumbnail('thumbnail');?>
Paul
  • 1,025
  • 1
  • 7
  • 16
  • I add with success the thumbnail to the RSS on ... but i can’t display the content of « image », how can i display this element in « item » ? – Marouy Jul 06 '19 at 06:52
  • try something like: `'.get_the_post_thumbnail('gallery').''; } ?>` – Paul Jul 06 '19 at 11:46
  • « Get_post_thumbnail() os not a recognize by SimplePie, i got an error.. – Marouy Jul 07 '19 at 08:58