Importing an RSS feed into post whilst using a custom field?
-
Hi,
Hope you can help with something. I currently have this code in my posts page:<?php if(function_exists('fetch_feed')) { include_once(ABSPATH . WPINC . '/feed.php'); // include the required file $feed = fetch_feed('RSS FEED ADDRESS HERE'); // 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 $feed->set_cache_duration (43200); } if ($limit == 0) echo '<div>The feed is either empty or unavailable.</div>'; else foreach ($items as $item) : ?> <div> <b><?php echo $item->get_title(); ?></b> </div> <div> <?php echo substr($item->get_description(), 0, 200); ?> </div> <br> <?php endforeach; ?>
This works great – simply enter a valid RSS feed into the place marked ‘RSS FEED ADDRESS HERE’ and it will display on the post.
What I would like your help with is making the ‘RSS FEED ADDRESS’ pull in the address from a custom field.
So, say I have two posts, both need to pull in a different RSS Feed.
I have a custom field named RSS and I’ve entered the RSS feed url in there.
How can I have it populate the code?
I can pull in the custom field no problem using`<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, ‘RSS’, true);
wp_reset_query();
?>`I just don’t know how to get it into that code.
I will then wrap an if statement around the whole thing so that if there is no custom field named RSS it won’t display.
Any help greatly appreciated.
Dan
- The topic ‘Importing an RSS feed into post whilst using a custom field?’ is closed to new replies.