Specifically, I am making a custom rss feed. I have modeled it after the rss2 feed that is in the wp-includes folder. I can successfully retrieve all posts using the standard query_posts('posts_per_page=-1').
Here is how I am attempting to get just the ones posted in the past year:
$today = date('Y-m-d');
$newdate = strtotime ( '-1 year' , strtotime ( $today ) ) ;
$ayearago = date( 'Y-m-d' , $newdate );
function filter_where($where = '') {
$where .= " AND post_date >= '" . $ayearago . "'";
return $where;
}
add_filter('posts_where', 'filter_where');
query_posts($query_string);
Yes this returns only posts from 2011 forward. Can someone help me figure out why?
Here is the main source code from my custom feed page called feed-postlist.php:
/**
* Custom RSS Feed
*
* @package WordPress
*/
header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
$more = 1;
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
<?php do_action('rss2_ns'); ?>
>
<?php
$today = date('Y-m-d');
$newdate = strtotime ( '-1 year' , strtotime ( $today ) ) ;
$ayearago = date( 'Y-m-d' , $newdate );
function filter_where($where = '') {
$where .= " AND post_date >= DATE('" . $ayearago . "')";
return $where;
}
add_filter('posts_where', 'filter_where');
query_posts('posts_per_page=-1');
?>
<channel>
<title><?php bloginfo_rss('name'); wp_title_rss(); ?></title>
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
<link><?php bloginfo_rss('url') ?></link>
<description><?php bloginfo_rss("description") ?></description>
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
<language><?php echo get_option('rss_language'); ?></language>
<sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod>
<sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency>
<?php do_action('rss2_head'); ?>
<?php while( have_posts()) : the_post(); ?>
<item>
Thanks,
Ryan
$query_string
but don't include the code where you assign it nor are you explaining the context in which you are callingquery_posts()
(which isn't a function that people should usually call; normallyget_posts()
or evennew WP_Query()
is better.)$query_string
toposts_per_page=-1
but it still does not return any data.