is_main_query() && is_feed() ) {
$query->query_vars['post_parent'] = 0;
$query->query_vars['meta_key'] = '_nd_stamp';
$query->query_vars['order'] = 'DESC';
$query->query_vars['orderby'] = 'meta_value_num';
return;
}
}
/**
* add NextDraft logo to archive RSS feed
*/
public function rss_logo() {
global $wp_query;
// bail on non RSS
if ( !isset( $wp_query->query_vars['feed'] ) )
return;
// check for our custom post type
if ( $wp_query->query_vars['post_type'] != 'nd-archives' )
return;
$logo = '';
$logo .= '';
$logo .= 'NextDraft';
$logo .= ''. plugins_url( 'lib/img/rss-logo.png', __FILE__ ) . '';
$logo .= ''. home_url() .'/current/';
$logo .= '144';
$logo .= '43';
$logo .= 'NextDraft';
$logo .= '';
echo $logo;
}
/**
* change main RSS title
*/
public function rss_main_title( $title ) {
global $wp_query;
// bail on non RSS
if ( !isset( $wp_query->query_vars['feed'] ) )
return $title;
// check for our custom post type
if ( $wp_query->query_vars['post_type'] == 'nd-archives' )
$title = ': The Day\'s Most Fascinating News';
return $title;
}
/**
* change RSS title to match first child element
*/
public function rss_item_title( $title ) {
global $post;
if ( $post->post_type !== 'nd-archives' )
return $title;
if ( $post->post_parent != 0 )
return $title;
$args = array(
'fields' => 'ids',
'post_type' => 'nd-archives',
'post_parent' => $post->ID,
'posts_per_page' => 1,
'meta_key' => '_nd_section_order',
'order' => 'ASC',
'orderby' => 'meta_value_num',
'suppress_filters' => false
);
$blurbs = get_posts( $args );
if ( ! $blurbs )
return $title;
$first = $blurbs[0];
$title = get_post_field( 'post_title', $first, 'raw' );
$title = trim( $title );
return $title;
}
public function rss_description( $excerpt ) {
global $post;
if ( $post->post_type !== 'nd-archives' )
return $excerpt;
if ( $post->post_parent != 0 )
return $excerpt;
$stamp = get_post_meta( $post->ID, '_nd_stamp', true );
$clean = date( 'F jS, Y', $stamp );
$excerpt = 'The Day\'s Most Fascinating News for '.$clean;
return $excerpt;
}
/**
* display child elements on RSS feed
*/
public function rss_content( $content ) {
global $post;
if ( $post->post_type !== 'nd-archives' )
return $content;
if ( $post->post_parent != 0 )
return $content;
$parent_id = $post->ID;
$args = array(
'fields' => 'ids',
'post_type' => 'nd-archives',
'post_parent' => $parent_id,
'nopaging' => true,
'meta_key' => '_nd_section_order',
'order' => 'ASC',
'orderby' => 'meta_value_num',
'suppress_filters' => false
);
$blurbs = get_posts( $args );
if ( ! $blurbs )
return $content;
// get optional announcement
$announce = get_post_meta( $parent_id, '_nd_announce', true );
$display = '';
$i = 1;
foreach ( $blurbs as $blurb_id ):
$title = get_post_field( 'post_title', $blurb_id, 'raw' );
$text = get_post_field( 'post_content', $blurb_id, 'raw' );
$link = get_permalink( $blurb_id );
$display .= '
';
$display .= '
';
if ( !empty( $announce ) && $i == 1 )
$display .= '
'.$announce.'
';
$display .= apply_filters( 'the_content', $text );
$display .= '
';
// add link to home page after 3rd blurb
if ( $i == 3 ) :
$display .= '';
endif;
$i++;
endforeach;
return $content.$display;
}