WordPress.org

Ready to get started?Download WordPress

Forums

How to use is_author in feeds? (7 posts)

  1. pampfelimetten
    Member
    Posted 5 years ago #

    Hi dear community,

    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 generated for the general homepage, or for a single user.

    But: It doesn't work at all - is_author and all the others is_* functions I tried always trigger false. is_feed works, but well, doesn't help me very much.

    So: How can I determine the request inside the rss feed?

    Thanks in advance!

  2. pampfelimetten
    Member
    Posted 5 years ago #

    nobody can help me?

  3. pampfelimetten
    Member
    Posted 5 years ago #

  4. Mark / t31os
    Moderator
    Posted 5 years ago #

    is_author and is_XXX type functions (generally) check to see if there is a set query var..

    So author would be a query like.

    yoursite.com?author=pampfelimetten
    yourstei.com/author/pampfelimetten

    Depending on your permalink settings.

    http://codex.wordpress.org/Conditional_Tags#An_Author_Page

  5. pampfelimetten
    Member
    Posted 5 years ago #

    Hi t31os_

    thanks for your answer!

    The problem is: They do work at:
    yoursite.com/author/pampfelimetten

    but NOT at:

    yoursite.com/author/pampfelimetten/feed

    Which, in my humble opinion is a bug.

    I can alter nearly every part of wp, and I think I should be able to alter the feeds of authors, categories, etc... independent to each other.

  6. Mark / t31os
    Moderator
    Posted 5 years ago #

    Is this on a test site or one i can see?

    If you're using a local install, print out your rewrite rules so you can check they exist..

    <pre><?php print_r( $wp_rewrite->rules ); ?></pre>

    localhost/author/admin/feed/ - works as expected for me..
    or
    localhost/author/testuser/feed/ - also works

    Perhaps you should try a pre_get_posts filter for managing the categories on feeds though..

  7. pampfelimetten
    Member
    Posted 5 years ago #

    @t31os:
    I wrote a workaround, also see trac ticket:

    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');

    I still think that there should be a better way to do stuff like that.

Topic Closed

This topic has been closed to new replies.

About this Topic