Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

In addition to the normal feed that wordpress produces, i need to publish an additional feed of posts that have a certain custom field value.

I'm a bit lost on where to start. Any tip?

share|improve this question
    
Do you mean an rss feed? Or do you just want multiple 'loops' of posts on a page? –  Zach L Oct 15 '11 at 18:07
    
yes i meant an RSS feed. Thx –  pixeline Oct 16 '11 at 20:24
add comment

1 Answer

up vote 2 down vote accepted

Something like this will add a /feed/special to your site.

add_feed('special','do_special_feed');

function do_special_feed() {
  query_posts(array(
    'meta_key' => 'key',
    'meta_value' => 'value',
  ));
  do_feed_rss2(false);
}

After putting it in a plugin or your theme's functions.php or what have you, you'll need to visit the Settings->Permalinks page at least once and save the settings, to get it to rebuild the permalink rules.

share|improve this answer
    
interesting. In the meantime i implemented a technique seen on Yoast, which works, but is more of a hack than your suggestion. yoast.com/custom-rss-feeds-wordpress –  pixeline Oct 16 '11 at 20:01
    
Yeah, that method of the Page Template seems like a pretty weird hack when the ability to do this sort of thing easily is already built right in to WordPress. Creating custom feeds is easy. –  Otto Oct 16 '11 at 21:54
    
I just tested this code. Any idea why after removing it from functions.php, the feed keeps available ? –  Simon Mar 22 '12 at 15:23
    
Permalinks require a visit to the permalinks page to change. Also, check your caching plugins, if you have any. –  Otto Mar 23 '12 at 3:15
add comment

Your Answer

 
discard

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.