Reputation: 11
I need to import some content from another Wordpress blog into my blog via RSS. The target blog contains some custom fields (like so: number_of_users) that I need to import as well. I am currently using the fetch_feed function to import the RSS feed and I don't know how to get the values of these custom fields.
Here is the code I use:
<?php if(function_exists('fetch_feed')) {
// include the required file
$feed = fetch_feed('http://domaintoimportfeedfrom.com/feed/'); // specify the source feed
$limit = $feed->get_item_quantity(7); // specify number of items
$items = $feed->get_items(0, $limit); // create an array of items
}
if ($limit == 0) echo '<div>The feed is either empty or unavailable.</div>';
else foreach ($items as $item) : ?>
<div>
<a href="<?php echo $item->get_permalink(); ?>"
title="<?php echo $item->get_date('j F Y @ g:i a'); ?>">
<?php echo $item->get_title(); ?>
</a>
// need to get the "number_of_users" custom field
</div>
<?php endforeach; ?>
Please advise.
Any other solution is also welcomed.
Upvotes: 0
Views: 221
Reputation: 1278
<?php
function getFeed($feed_url) {
$content = file_get_contents($feed_url);
$x = new SimpleXmlElement($content);
echo "<ul>";
foreach($x->channel->item as $entry) {
echo "<li><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></li>";
}
echo "</ul>";
}
?>
<?php getFeed("http://domaintoimportfeedfrom.com/feed/"); ?>
http://code.tutsplus.com/articles/how-to-read-an-rss-feed-with-php-screencast--net-1272
Upvotes: 1