开发者

Query multiple categories in WordPress

开发者 https://www.devze.com 2023-01-06 10:34 出处:网络
The WP codex says to query posts from different categories I use this: query_posts(\'cat=2,6,17,38\');

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

0

精彩评论

暂无评论...
验证码 换一张
取 消