Query multiple categories in WordPress
The WP codex says to query posts from different categories I use this:
query_posts('cat=2,6,17,38');
I am doing that in this (http://pastebin.com/69WTBi8Q) script to display rss feed from various categorie开发者_JAVA百科s, but it's only showing the first category in the string. http://dev.liquor.com/custom-rss-feed/
Why?
Well, there are a couple of things you need to do differently. That code isn't outputting RSS, since you're sending the headers way too late. It's rendering as text/html, not application/xml. You can query posts telling it to make a feed:
query_posts(array(
'cat' => '2,6,17,38',
'feed' => 'rss2'
));
To fix the category problem, try doing this:
query_posts(array(
'category__in' => array(2,6,17,38),
'feed' => 'rss2'
));
You need to hook this onto a hook any time after 'init' but no later than 'wp_loaded'.
精彩评论