Opened 15 years ago
Closed 8 years ago
#11053 closed enhancement (duplicate)
Conditional Tags should work in feeds as well
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.8.5 |
Component: | Feeds | Keywords: | needs-patch |
Focuses: | Cc: |
Description
I try to get the following to work:
function xxx_filter_cat() { if (is_author()) query_posts("cat=4"); if (is_front_page()) query_posts("cat=2,3"); } add_action('rss2_head', 'xxx_filter_cat');
It should alter the rss2 feed, depending if it should get generated for the general homepage, or for a single author.
But: It doesn't work at all - is_author and all the other is_* functions I tried always trigger false. is_feed works, but well, doesn't help me very much.
It would be easy to manipulate the generated feeds if wp would support the already built-in conditional tags in the feeds as well.
Change History (7)
#3
@
15 years ago
Ups, small typo, should be:
function xxx_filter_rss() { $uri= explode("/", $_SERVER['REQUEST_URI']); if ($uri[1]=="author") { global $wpdb; $name = $wpdb->get_var("SELECT display_name FROM $wpdb->users WHERE user_nicename='".$uri[2]."'"); query_posts("cat=2,3&meta_key=xxx&meta_value=".$name."&showposts=10"); } else { query_posts("cat=2,3"); }; } add_action('rss2_head', 'xxx_filter_rss');
#6
@
8 years ago
As of 4.7.2 the description needs an update.
As it currently stands, some of the "is_" functions do function as expected on feed pages and some don't.
is_archive()
, is_category()
, is_author()
are all fine.
However, is_home()
and is_front_page
, is_singular
do not work in combination with Feeds. This is a reported issue here: #20899 which requires some delicate patching since in order not to cause problems for plugin authors that are accustom to the existing behavior.
I have found a working solution. Not very elegant, but it does the job until the conditional tags work as well: