2

Using Wordpress 3, creating write panels with Magic Fields, how do I add custom fields to my RSS feed?

For example, I have an 'image of the day' write panel, with a custom field for the photo credit. How can I include all that as part of my feed?

Thanks.

2

you can use something like this

function feed_magic_fields( $content ) {
  global $post, $id;

  if ( !is_feed() )
    return $content;

  // is feed
  $date = get('date_event');
  if( $date)
    $content .= $date

  return $content; 
}

add_filter( 'the_content', 'feed_magic_fields' );
| improve this answer | |
  • thanks for adding some code, that's basically what I meant no need to global $post, $id btw. – hakre Aug 27 '10 at 21:21
0

You can hook into your feed with the according filters and then add your stuff.

Basically that codex page suggests (and that's still valid, you find the feed templates inside /wp-includes/, the files start with feed-) that you hook into the_content and you check with is_feed() if you need to modify the content for the feed.

To save you some hassles, you can register your whole plugin to activate on the do_feed_rss2 (or whichever you use) hook, so you do not need to check for is_feed().

The contents of magic fields (custom fields to be precise) can be read out with existing functions, you find the documentation here: Custom Fields.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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