简体   繁体   中英

Wordpress - How to get a custom field from another wordpress blog via RSS

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.

<?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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM