tags:

views:

12

answers:

1

So 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 categories, but it's only showing the first category in the string. http://dev.liquor.com/custom-rss-feed/

why?

+1  A: 

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'.

John P Bloch
TY So much. so it seems you can't put an array in a string so we made our own array here? and the variable is equal to the array?
HollerTrain
Well, if you have the categories formatted as a comma separated string (say, `$cat_string`), you could get them into an array by using `$categories = explode(',', $cat_string);`.
John P Bloch