Title: RSS feed date
Last modified: February 9, 2022

---

# RSS feed date

 *  [webexs](https://wordpress.org/support/users/webexs/)
 * (@webexs)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/rss-feed-date/)
 * I have made a custom RSS feed.
 *     ```
       <?php
   
       $postCount = 6;
       $posts = query_posts(
           'showposts='.$postCount.
           '&category_name= mail'
       );
   
       header('Content-Type: '.feed_content_type('rss-http').'; charset='.get_option('blog_charset'), true);
       echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>';
       ?>
   
       <rss version="2.0">
       <channel>
           <title><?php bloginfo_rss('name'); ?> - Feed</title>
           <link><?php bloginfo_rss('url') ?></link>
           <description><?php bloginfo_rss('description') ?></description>
           <?php while(have_posts()) : the_post(); ?>
               <item>
                   <title><?php the_title_rss(); ?></title>
                   <guid isPermaLink="true"><?php the_guid(); ?></guid>
                   <?php if (has_post_thumbnail( $post->ID ) ): ?>
                       <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
                       <enclosure url="<?php echo $image[0]; ?>" type="image/jpeg" />
                   <?php endif; ?>
                   <pubDate><?php echo mysql2date('D, d M Y H:i:s', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
               </item>
           <?php endwhile; ?>
           <?php wp_reset_query(); ?>  
       </channel>
       </rss>
       ```
   
 * and i want the last 7 days of posts with category mail.
 * i have tryed this one and it works on site.com/feed/ but not on site.com/feed/
   admin/
 *     ```
       function wpse334869_filter_feed( $query ) {
           if( $query->is_feed('admin') ) {
               $query->set( 'date_query', array(
                   array(
                       'after' => '7 days ago'
                   )
               ) );
           }
       }
       add_action( 'pre_get_posts', 'wpse334869_filter_feed' );
       ```
   
 * How can i do this?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/rss-feed-date/#post-15348890)
 * Have you added “admin” as a new feed type?
    [https://developer.wordpress.org/reference/functions/add_feed/](https://developer.wordpress.org/reference/functions/add_feed/)
 * You’d normally get a category feed by including it in the request:
    _example.
   com/category/foo/feed/_ But you can force a category in “pre_get_posts” by setting
   the “category_name” query var.
 *  Thread Starter [webexs](https://wordpress.org/support/users/webexs/)
 * (@webexs)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/rss-feed-date/#post-15351486)
 * [@bcworkz](https://wordpress.org/support/users/bcworkz/) i have added the feed
   and i can see it but this code dosent work on my own mysite.com/feed/admin but
   it works on mysite.com/feed . I want too see the posts for the last 7 days in
   my feed/admin
 *     ```
       function wpse334869_filter_feed( $query ) {
           if( $query->is_feed('admin') ) {
               $query->set( 'date_query', array(
                   array(
                       'after' => '7 days ago'
                   )
               ) );
           }
       }
       add_action( 'pre_get_posts', 'wpse334869_filter_feed' );
       ```
   
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/rss-feed-date/#post-15351839)
 * Have you done anything to allow WP to recognize `/feed/admin/` requests? Like
   adding a rewrite rule to match such a request, then adding a `?feed=admin` query
   string to the rewritten URL.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘RSS feed date’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 3 replies
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [4 years, 3 months ago](https://wordpress.org/support/topic/rss-feed-date/#post-15351839)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
