admin管理员组文章数量:1024666
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.
1 Answer
Reset to default 1As 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')
.
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.
1 Answer
Reset to default 1As 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')
.
本文标签: How to add filter in custom rss feed
版权声明:本文标题:How to add filter in custom rss feed 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745524951a2154481.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论