How can I modify RSS item titles to be either the title or a custom meta field?
-
16-10-2019 - |
Question
I'd like to optionally replace some RSS item titles with a headline meta field I've added to certain post types.
I have the post types showing up in the feed using:
function myfeed_request($qv) {
if (isset($qv['feed']) && !isset($qv['post_type']))
$qv['post_type'] = array('post', 'interviews', 'reviews');
return $qv;
}
add_filter('request', 'myfeed_request');
But I've searched around and can't figure out how to replace the title. Any ideas?
Solution
Something like this (not tested):
add_filter('the_title_rss', 'custom_feed_title');
function custom_feed_title($title) {
$headline = get_post_meta(get_the_id(), 'headline', true);
if (!empty($headline))
return $headline;
return $title;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange