How to add filter in custom rss feed

I have this code for my 2 custom rss feeds:add_action( 'init', 'custom_feeds' );function custom_fee

I have this code for my 2 custom rss feeds:

add_action( 'init', 'custom_feeds' );
function custom_feeds()
{
    foreach( array( 'custom1', 'custom2' ) as $name )
    {
        add_feed( $name, 
            function() use ( $name )
            {
                get_template_part( 'rss', $name );  
            }
        );
    }
}

function feedFilter($query) {
    if ($query->is_feed) {
        $query->set('cat', '7');
        $query->set('posts_per_page','5');
    }
    return $query;
}
add_filter('pre_get_posts','feedFilter');

I wanted to put filter on custom2 only, like filter the feed by category 7 only; But my filter is affecting all the rss feeds.

I have this code for my 2 custom rss feeds:

add_action( 'init', 'custom_feeds' );
function custom_feeds()
{
    foreach( array( 'custom1', 'custom2' ) as $name )
    {
        add_feed( $name, 
            function() use ( $name )
            {
                get_template_part( 'rss', $name );  
            }
        );
    }
}

function feedFilter($query) {
    if ($query->is_feed) {
        $query->set('cat', '7');
        $query->set('posts_per_page','5');
    }
    return $query;
}
add_filter('pre_get_posts','feedFilter');

I wanted to put filter on custom2 only, like filter the feed by category 7 only; But my filter is affecting all the rss feeds.

Share Improve this question edited May 4, 2019 at 3:37 Fayaz 9,0172 gold badges33 silver badges51 bronze badges asked Jun 11, 2018 at 6:40 crissycrissy 35 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

As you can see from the source is_feed takes a parameter, so you should be able to restrict the query by using $query->is_feed('custom_rss2').

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745524952a4631426.html

相关推荐

  • How to add filter in custom rss feed

    I have this code for my 2 custom rss feeds:add_action( 'init', 'custom_feeds' );function custom_fee

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信