THANK YOU THANK YOU for this excellent piece of information.
I wanted to extend what the other two have written already...
For this to validate, you must have a custom namespace.
Here's how you do that:
/* IN ORDER TO VALIDATE you must add namespace */
add_action('rss2_ns', 'my_rss2_ns');
function my_rss2_ns(){
echo 'xmlns:mycustomfields="'. get_bloginfo('wpurl').'"'."\n";
}
And then prefix the field name item with the custom namespace
In this example, I've used "mycustomfields"
See below:
/* add elements */
add_action('rss2_item', 'yoursite_rss2_item');
function yoursite_rss2_item() {
if (get_post_type()=='my_custom_post_type') {
$fields = array( 'field1', 'field2', 'field3' );
$post_id = get_the_ID();
foreach($fields as $field)
if ($value = get_post_meta($post_id,$field,true))
echo "<mycustomfields:{$field}>{$value}</mycustomfields:{$field}>\n";
}
}
On a side note you can use an action to hook into any of the 3
rss2_ns : to add a specific namespace
add_action('rss2_ns', 'my_rss2_ns');
rss2_head : to add tags in the feed header
add_action('rss2_head', 'my_rss2_head');
rss2_item : to add tags in each feed items
add_action('rss2_item', 'my_rss2_item');