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); }