| How to save WordPress RSS Feed to a File?
|
ispreview

msg:4424740 | 5:10 pm on Mar 4, 2012 (gmt 0) | As per the topic title, I actually want to do two things but we'll start with the first. Essentially I want to save my RSS feed output..
http://www.mysite.co.uk/index.php/feed (I also tried with the following url - both work when you use them in a browser)
http://www.mysite.co.uk/index.php?feed=rss ..to a static file like feed.xml or feed.txt. I tried CURL, which works with all my other PHP systems for similar tasks, but something about WP prevents it from working.
<?php function get_data($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch); curl_close($ch); return $data; }
$returned_content = get_data('http://www.mysite.co.uk/index.php?feed=rss');
echo $returned_content;
$fp = fopen("feed.txt", "w"); fwrite($fp, $returned_content); fclose($fp); ?> Likewise when I try to rewrite (htaccess) any WP URL (this happens regardless of whether I use WP's pathinfo or mod_rewrite solution for pretty URLs) to another, such as telling requests for "/feed.xml" to pull their data from "/index.php/feed" .. it also fails but produces a 404 (note that WP's feed links do actually work). I think I tried some like this: RewriteRule ^meow\.xml$ index\.php?feed=rss [QSA,L] and also tried RewriteRule ^meow.xml(/?)+$ index.php?feed=rss [QSA,L] No dice. I don't have any WP code in my ROOT htaccess because I'm using Pathinfo. Any ideas on either or those two problems?
|
ispreview

msg:4424980 | 9:48 am on Mar 5, 2012 (gmt 0) | I had some sucess with this: RewriteRule ^news\.xml$ /index.php?feed=rss2 [L] That makes mysite.co.uk/rss2.xml work but if I put that into mysite.co.uk/news/rss2.xml (as below) then it returns one of WP's "this is not a valid feed template" errors. RewriteRule ^news/rss2.xml$ index.php?feed=rss2 How can I get around this?
|
iamzippy

msg:4427582 | 6:43 pm on Mar 10, 2012 (gmt 0) | Are we talking here about a server making an http connection to itself?
|
londrum

msg:4427590 | 7:25 pm on Mar 10, 2012 (gmt 0) | you could try recreating the feed yourself, which is pretty easy. all you've got to do is put a new function inside the functions.php file (in the same directory as your theme) then you could output the results as a simple .txt file, or you could save the output to a buffer and then store it as a file on your server -- bypassing CURL completely. you've just got to include whatever you want inside the function and wordpress will take care of the rest. here is a little example of how you can create a feed.
function NAME_OF_YOUR_FEED() {
header('Content-Type: text/xml; charset='.get_option('blog_charset'), true);
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
echo '<channel>';
<title>Title</title>
<link>http://www.example.com/?feed=NAME_OF_YOUR_FEED</link>
<atom:link href="http://www.example.com/?feed=NAME_OF_YOUR_FEED" rel="self" type="application/rss+xml" />
// build the feed here with a loop, using query_posts(), or whatever
echo '</channel>';
echo '</rss>'; }
add_feed('NAME_OF_YOUR_FEED','NAME_OF_YOUR_FEED');
|
|
|