Make WordPress Core

Opened 15 years ago

Closed 8 years ago

#11053 closed enhancement (duplicate)

Conditional Tags should work in feeds as well

Reported by: pampfelimetten's profile pampfelimetten 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)

#1 @scribu
15 years ago

  • Milestone changed from Unassigned to Future Release

#2 @pampfelimetten
15 years ago

I have found a working solution. Not very elegant, but it does the job until the conditional tags work as well:

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=xxxmeta_value=".$name."&showposts=10");
	} else {

		query_posts("cat=2,3");
	};

}

add_action('rss2_head', 'xxx_filter_rss');

#3 @pampfelimetten
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');

#4 @SergeyBiryukov
12 years ago

  • Keywords conditional tags feeds removed

Related: #20899

#5 @stevenkword
10 years ago

  • Keywords needs-patch added

Related: #20899

#6 @stevenkword
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.

Last edited 8 years ago by stevenkword (previous) (diff)

#7 @stevenkword
8 years ago

  • Milestone Future Release deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #20899.

Note: See TracTickets for help on using tickets.