Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This is how I'm adding a featured image to my RSS:

function featuredtoRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '' . get_the_post_thumbnail( $post->ID, 'topImage', array( 'style' =>  'margin:0 auto; border: 1px solid #555; display:block;' ) ) . '' . $content;
}
return $content;
}

add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');

All of my posts have audio attachments (one per post), and I would like to add them to RSS as well. How would I achieve that?

Thanks in advance.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You can add this part into your function:

$audios =& get_children('post_type=attachment&post_parent='.$post->ID.'&post_mime_type=audio' );
foreach ( $audios as $id => $audio ){ 
    $content.='<a href="'.wp_get_attachment_url($id).'" target="_blank">'.$audio->post_title.'</a> ';
} 

to add audio links into your feed content.

I'm using get_children() here, you can read more about it here:

http://codex.wordpress.org/Function_Reference/get_children

Edit:

Here is the whole function:

function featuredtoRSS($content) {
    global $post;

    if ( has_post_thumbnail( $post->ID ) ){
        $content = '' . get_the_post_thumbnail( $post->ID, 'topImage', array( 'style' =>  'margin:0 auto; border: 1px solid #555; display:block;' ) ) . '' . $content;
    }

    $audios =& get_children( 'post_type=attachment&post_parent='.$post->ID.'&post_mime_type=audio' );
    foreach ( $audios as $id => $audio ){ 
        $content.='<a href="'.wp_get_attachment_url($id).'" target="_blank">'.$audio->post_title.'</a> ';
    } 

    return $content;
}

add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');
share|improve this answer
    
Thanks. Would you please help me assemble the whole function? –  pereyra Feb 13 '13 at 23:43
    
sure, I added the updated function above. –  birgire Feb 14 '13 at 4:05
    
Yep, that's how I did it initially (thank you very much though). There's a problem though: this is what WP adds to the feed: <a target="_blank" href="<a href='domain.com/correct-link-to.mp3'; title='post title'>post title</a>" xml:base='domain.com/path/to/feed/'>post title</a> –  pereyra Feb 14 '13 at 15:35
    
I've figured it out, one needs to use wp_get_attachment_url instead of wp_get_attachment_link. –  pereyra Feb 14 '13 at 15:49
    
ok great ;-) I will update the code example. –  birgire Feb 14 '13 at 16:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.