[wp-trac] [WordPress Trac] #22031: Conditional tags don't work within add_feed() callback function
WordPress Trac
wp-trac at lists.automattic.com
Fri Sep 28 14:00:34 UTC 2012
#22031: Conditional tags don't work within add_feed() callback function
--------------------------+------------------------------
Reporter: sanchothefat | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Feeds | Version:
Severity: normal | Resolution:
Keywords: close |
--------------------------+------------------------------
Changes (by ocean90):
* keywords: dev-feedback => close
Comment:
It doesn't make sense to return true for `is_home` or `is_singular` in a
feed. It's a feed so `is_feed` returns true. You need to define your own
query for the feed content.
Example:
{{{
add_feed( 'my-feed', 'my_feed_template' );
function feed_template() {
load_template( ABSPATH . WPINC . '/feed-rss2.php' );
}
add_action( 'pre_get_posts', 'my_feed_content' );
function feed_content( $query ) {
// Bail if $posts_query is not an object or of incorrect class
if ( ! is_object( $query ) || ( 'WP_Query' != get_class( $query )
) )
return;
// Bail if filters are suppressed on this query
if ( $query->get( 'suppress_filters' ) )
return;
if ( ! $query->is_feed( 'my-feed' ) )
return;
$query->set( 'post_type', array( 'post', 'page' ) );
}
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/22031#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list