WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create a custom rss feed

Template Name: Custom Feed

function filter_where($where = '') {
    //posts in the last 30 days
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-2 days')) . "'";
    return $where;
add_filter('posts_where', 'filter_where');
      'post_type' => 'post',
      'post_status' => 'publish',
      'showposts' => -1,
      'caller_get_posts'=> 1
$my_query=new WP_Query($args);
remove_filter('posts_where', 'filter_where');
header("Content-Type: application/rss+xml; charset=UTF-8");
echo '<?xml version="1.0"?>';
?><rss version="2.0">
  <description>The latest blog posts from #</description>
  if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <title><?php the_title(); ?></title>
    <link><?php the_permalink() ?></link>
  } //if ($my_query)?>
<?PHP wp_reset_query(); //just in case

Now the final code for Custom Rss feed fetch from 48 hours. I can get right results from it.

Thanks for your help.

Mohammad Umer

share|improve this question
up vote 0 down vote accepted

Never tested this ,but i believe you need to add WHERE clause to your query with time difference like so :

$timediff .= " AND post_date > '" . date('Y-m-d', strtotime('-2 days')) . "'";

you can find it also in the codex


If you do not want to use on query, but inside the loop, you could also do

<?php while (have_posts()) : the_post(); ?>

<?php $mylimit=15 * 86400; //days * seconds per day
$post_age = date('U') - get_post_time('U');
if ($post_age < $mylimit) { ?>

// your functions or display here 

<?php } ?>
<?php endwhile; ?>
share|improve this answer
You give me right way but not complete function here is compete function – Mohammad Umer Jan 9 '12 at 7:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.