Add Custom postmeta Fields to Custom Post Type RSS in wordpress

You can add that to your theme’s functions.php and it will work, though I can’t vouch for the validity of the feed. I don’t know the XML/RSS standards very well. I’d have to research it.

You may be better off creating a simple plugin for this since theme edit will get overwritten when you update the theme.

class My_Alter_RSS {
 function __construct() {
  add_action('rss2_item', array($this,'add_custom_fields_to_rss'));
 }

 function add_custom_fields_to_rss() {
    if(get_post_type() == 'my_custom_post_type') {
      $my_meta_value = get_post_meta(get_the_ID(), 'my_meta_key', true);
      if (empty($my_meta_value)) return false;
      ?>
      <my_meta_value><?php echo $my_meta_value ?></my_meta_value>
      <?php
    }
  }
}
$my_alter_rss = new My_Alter_RSS;

I’ll leave you to work out the correct file headers for that plugin.

You really should take some time to work out the basics of PHP and WordPress. Copying and pasting code you find on the web and don’t understand is not safe. You can introduce bugs, unsafe code, or even positively malicious code.