Title: Custom RSS feed and codex code issue
Last modified: August 20, 2016

---

# Custom RSS feed and codex code issue

 *  [slideaway](https://wordpress.org/support/users/modsuperstar/)
 * (@modsuperstar)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/custom-rss-feed-and-codex-code-issue/)
 * I have been trying to implement the code from [http://codex.wordpress.org/Customizing_Feeds](http://codex.wordpress.org/Customizing_Feeds)
   for building a custom RSS template and can’t seem to get it to work properly.
   I don’t believe any of the changes I made should have messed it up, so it has
   me wondering if the codex code does work.
 *     ```
       remove_all_actions( 'do_feed_rss2' );
       add_action( 'do_feed_rss2', 'lw_events_rss2', 10, 1 );
   
       function lw_events_rss2( $for_comments ) {
           $rss_template = get_template_directory() . '/events-rss2.php';
           if( get_query_var( 'post_type' ) == 'event' and file_exists( $rss_template ) )
               load_template( $rss_template );
           else
               do_feed_rss2( $for_comments ); // Call default function
       }
       ```
   
 * Can anyone shed some light on what I might be messing up here?

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

 *  Thread Starter [slideaway](https://wordpress.org/support/users/modsuperstar/)
 * (@modsuperstar)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/custom-rss-feed-and-codex-code-issue/#post-2659579)
 *     ```
       function lw_events_rss2( $for_comments ) {
           $rss_template = get_template_directory() . '/events-rss2.php';
           if( get_post_type( $post->ID ) == 'event' and file_exists( $rss_template ) )
               load_template( $rss_template );
           else
               do_feed_rss2( $for_comments ); // Call default function
       }
       ```
   
 * I had to change the if to get_post_type and it seems to work now. I’m curious
   if anyone else can get the codex code to work for them, or if that example might
   be messed up and should be changed.
 *  Thread Starter [slideaway](https://wordpress.org/support/users/modsuperstar/)
 * (@modsuperstar)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/custom-rss-feed-and-codex-code-issue/#post-2659636)
 * Turns out there must have been some caching issue and that didn’t actually fix
   my issue. Back to the original question I guess. It seems that _get\_query\_var(‘
   post\_type’ ) == ‘event’_ is what is failing in this, but I haven’t been able
   to figure out an alternative that will hit just the event pages.

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

The topic ‘Custom RSS feed and codex code issue’ is closed to new replies.

## Tags

 * [RSS](https://wordpress.org/support/topic-tag/rss/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 1 participant
 * Last reply from: [slideaway](https://wordpress.org/support/users/modsuperstar/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/custom-rss-feed-and-codex-code-issue/#post-2659636)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
