[Resolved] How can I add taxonomy terms to the Custom Post Type RSS feed?
This support ticket is created 5 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I am using the WP feed to create an automated newsletter mail out in MailChimp.
Currently it posts a new newsletter each month containing a list of any new posts during that period.
The ToolSet custom post type is "Events".
I can get it to return the post title as a link and the post body excerpt. I would like to be able to show the custom taxonomy (Event Type / Location) terms for each post as well.
How can I expose the custom post taxonomy within hidden link RSS
in order to add it in a newsletter?
You already have a feed for your event custom post type, but you want to customise what is included in the feed so that the assigned custom taxonomy terms are included in the field, right?
I'm no expert in this, but it seems to me you have two options.
<?php
add_action('rss2_item', 'add_my_custom_field_node');
function add_my_custom_field_node() {
global $post;
$metaValue = get_post_meta($post->ID, 'my-custom-field', true);
if(!empty($metaValue)):
echo("<my-custom-field>{$metaValue}</my-custom-field>");
endif;
}
?>
1. If I want to add a custom field to the RSS feed, "my-custom-field" is the value of the field slug, correct?
2. If I want the taxonomy term for the item (e.g. event type, location) how would this code be different?
1. Yes, you need to replace the my-custom-field of the get_post_meta call with the slug of your custom field. Remember that Types fields use a wpcf- prefix, e.g. 'wpcf-my-custom-field'. I don't know, but I doubt that the my-custom-field tags that are echoed need to be the slug as such, the opening and closing tags probably just need to match and be distinct from other such tags.
I've discovered that WordPress uses a 12 hour cache for RSS feeds.
Which would explain why I'm not seeing the changes after implementing your code above. hidden link
I've tried this code snippet but it doesnt do anything.
function return_cache_time( $seconds )
{
// change the default feed cache recreation period to 60 secs
return (int) 60;
}
//set feed cache duration
add_filter( 'wp_feed_cache_transient_lifetime', 'return_cache_time');
So I will have to wait up to 12 hours to see if the date formating code snippet above works.
But I have every confidence that it should.
Will update this ticket later in the day.