Quantcast
Viewing latest article 1
Browse Latest Browse All 2

Answer by Simon Pollard for Insert RSS Feeds as WP posts

If you are able to code PHP its easy to loop through an RSS feed and insert the data into WordPress. I usually create a new post type (though of course you can use the default 'post' type). In the example below I am using a post type I made called 'article'.

There are many ways to loop through an RSS feed, here is what I use:

$rss = new DOMDocument();$rss->load($rss_url);// Loop through each item in the feedforeach ($rss->getElementsByTagName('item') as $node) {  // Code goes here  // Example to get a value  // Define a namespace  $ns = 'http://purl.org/rss/1.0/modules/content/';  $content = $node->getElementsByTagNameNS($ns, 'encoded');  $content = $content->item(0)->nodeValue;}

In the loop through your RSS feed get the data and save as variables, then run the following:

$new_article = array('post_title'    => $title,'post_content'  => $content,'post_excerpt'  => $description,'post_type'     => 'article','post_date'     => date('Y-m-d H:i:s',strtotime($date)),'post_author'   => 1,'post_status'   => 'publish');wp_insert_post( $new_article , true );

Adjust as needed to fit your needs.

Hope that helps, it will give you a lot more control than a plugin.


Viewing latest article 1
Browse Latest Browse All 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>