Make WordPress Core

Opened 17 years ago

Closed 9 years ago

#11053 closed enhancement (duplicate)

Conditional Tags should work in feeds as well

Reported by: pampfelimetten Owned by:
Priority: normal Milestone:
Component: Feeds Version: 2.8.5
Severity: normal Keywords: needs-patch
Cc: Focuses:

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
17 years ago

  • Milestone UnassignedFuture Release

#2 @pampfelimetten
17 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
17 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
13 years ago

  • Keywords conditional tags feeds removed

Related: #20899

#5 @stevenkword
11 years ago

  • Keywords needs-patch added

Related: #20899

#6 @stevenkword
10 years ago

As of 4.7.2 the description needs an update.

As it currently stands, some of the "is_" functions do work 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.

Version 0, edited 10 years ago by stevenkword (next)

#7 @stevenkword
9 years ago

  • Milestone Future Release
  • Resolutionduplicate
  • Status newclosed

Duplicate of #20899.

Note: See TracTickets for help on using tickets.