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.
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)) {
        ?>
        <my_meta_value><?php echo $my_meta_value ?></my_meta_value>
        <?php
    }
}
add_action('rss2_item', 'add_custom_fields_to_rss');

i have see this code. Can you give me the page name where i implement this in wordprss.

share|improve this question
    
I can give you a link where you can learn how to code for WordPress: codex.wordpress.org/Writing_a_Plugin –  Eugene Manuilov Feb 19 '13 at 13:02

1 Answer 1

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.

share|improve this answer

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.