Poniamo che vogliate recuperare da un vostro sito in PHP (non necessariamente in WordPress) titolo, permalink, riassunto e immagine di uno o più post di un vostro blog in WordPress.
Se la necessità fosse poi di impaginare questi elementi a piacimento nella vostra pagina del sito, non è una buona idea inserire l’immagine direttamente nei post del vostro blog, perché la posizione e lo stile dell’immagine sarebbe difficile da gestire in modo autonomo e l’immagine sarebbe visibile nel feed.
Una soluzione possibile è di distribuire l’immagine in evidenza o la prima immagine disponibile come allegato (enclosure) del feed.
Questo il codice da inserire nel file functions.php del tema del vostro blog:

function wporg_thumb_rss() {
global $post;
$first_img = "";
if (has_post_thumbnail($post->ID)) {
   $first_img=wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(150,150));
   $first_img=$first_img[0);
   $mime = get_post_mime_type(get_post_thumbnail_id($post->ID));
   $size = filesize(get_attached_file(get_post_thumbnail_id($post->ID)));
} 
else {
$ai = get_posts(array( 
 'post_type' => 'attachment', 
 'numberposts' => 1, 
 'post_status' => null, 
 'post_parent' => $post->ID,
 'post_mime_type' => 'image'
 )); 
if ($ai) {  
 foreach ($ai as $attachment) {  
   $first_img = wp_get_attachment_image_src($attachment->ID, array(150,150));
   $first_img=$first_img[0);
   $mime = get_post_mime_type($attachment->ID);
   $size = filesize(get_attached_file($attachment->ID));
 } 
 } 
}
echo '<enclosure url="'.$first_img.'" length="'.$size.'" type="'.$mime.'">';
}</enclosure>
<enclosure url="'.$first_img.'" length="'.$size.'" type="'.$mime.'">
add_filter('rss2_item', 'wporg_thumb_rss');</enclosure>

Il codice per recuperare uno o più post nel vostro sito e l’immagine allegata è il seguente:

function wporg_get_post_from_rss($link,$items) {
 $simple = simplexml_load_file($link);
 for($i=0;$i< $items;$i+=1)  {
$title = $simple->channel->item[$i)->title; 
$description =  $simple->channel->item[$i)->description; 
$content = $simple->channel->item[$i)->children("content", true); 
$data = $simple->channel->item[$i)->pubDate = date("d-m-Y",strtotime((string)($simple->channel->item[$i)->pubDate)));
$link = $simple->channel->item[$i)->link;
$image = $simple->channel->item[$i)->enclosure->attributes()->url;
  }
}

wporg_get_post_from_rss('https://my_site_url/feed/',1)