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.

I'm trying to extend an RSS feed to output some post-meta from my website.

I have an 'event_date' meta-key and I need to order by this as opposed to the RSS standard publish date, which I know how to do if I could get that information.

I'm using the following code, which makes use of the Wordpress action hooks available in the RSS feeds. However, when I use these hooks, the feeds report that there are no items found, while without these the items are found, but of course I cannot order them as I need.

Am I doing something wrong in the way that I am outputting to the RSS feed?

/**
 * Adds the 'event_date' meta value to a feed
 */
add_action('atom_entry', 'add_event_date_to_feed');
add_action('rdf_item', 'add_event_date_to_feed');
add_action('rss_item', 'add_event_date_to_feed');
add_action('rss2_item', 'add_event_date_to_feed');
function add_event_date_to_feed(){

    global $post;

    $event_date_raw = get_post_meta($post->ID, 'event_date', true);
    if($event_date_raw && $event_date_raw !== '') :
        $date_object = DateTime::createFromFormat('D, d M Y H:i:s +0000', $event_date_raw);
        $event_date = $date->format('U');
    else : 
        $event_date = '';
    endif;
    printf("\t\t".'<eventDate>%1$s</eventDate>'."\n", $event_date);

}
share|improve this question

1 Answer 1

WordPress uses SimplePie for reading feeds, not for generating feeds. You're looking at two different things here:

  1. You want to output your custom post meta in an RSS feed.
  2. You want to read that custom post meta somewhere else.

The first part is pretty easy. WordPress supports custom RSS feed templates. You can actually replace the standard RSS feed with a custom one that includes your custom post meta.

As for consuming the custom data, that is pretty straight-forward. SimplePie will read the RSS feed and create a feed object that includes everything that was in the XML file. Just work with it like you would any other object.

share|improve this answer
    
Thanks for the explaination, I was not aware that SimplePie was only a reader. I have now amended all the templates for generating the output, but I understnad that there is a Cache Time for RSS that needs to expire before a new set of data is created, so I will wait patiently until that time to test these changes. Thanks. –  David Gard Jul 11 '12 at 8:32
    
I have tried a solution derived from you answer, but sadly it is causing my feeds to fail. I have now ammended my question to better reflect my original query, and I have added this problem. I'd be greatful for any further assistence that you can give. Thanks. –  David Gard Jul 11 '12 at 9:16

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.