WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 20 months ago

#11053 new enhancement

Conditional Tags should work in feeds as well

Reported by: pampfelimetten Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 2.8.5
Component: Feeds Keywords:
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 (4)

comment:1 @scribu5 years ago

  • Milestone changed from Unassigned to Future Release

comment:2 @pampfelimetten5 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');

comment:3 @pampfelimetten5 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');

comment:4 @SergeyBiryukov20 months ago

  • Keywords conditional tags feeds removed

Related: #20899

Note: See TracTickets for help on using tickets.