The problem: I have a custom post type "announcements" and a custom taxonomy "announcements_taxonomy". I can access the RSS feed by going to http://domain.com/announcements/feed - The problem is I can not see the categories/tags in the RSS feed.

Detail: I am using Simplepie to get the feed items and show them outside of a WordPress install. Because the RSS feed on my WP site does not show the categories I can not access them with the get_categories() function.

Question: How can I get categories from my custom post type and taxonomy to show in the RSS feed?

  • 1
    Is the RSS feed your only option? What about using the REST API instead? That would expose whatever you like to your external site.
    – WebElaine
    Dec 19, 2017 at 14:26
  • I suppose not but I have not worked with the WP Rest API yet so the RSS Feed was my go to option
    – Derek
    Dec 19, 2017 at 15:24
  • For anyone looking to do this with the REST API, here is a nice URL for a beginners guide to how to use it for this test case: css-tricks.com/using-the-wp-api-to-fetch-posts
    – Derek
    Dec 19, 2017 at 20:12

1 Answer 1


Here is how to show taxonomy terms in rss feed. Just add this to the functions.php file and update the $tax and $post_type variables to match your needs.:

add_filter('the_category_rss', 'wpq_the_category_rss');
add_filter('rss2_ns', 'wpq_rss2_ns');

function wpq_the_category_rss($the_list_original)
$tax = 'announcement_tags';
$post_type = 'announcements';

if(get_post_type() != $post_type)
return $the_list;

$categories = get_the_terms(get_the_ID(), $tax);

$the_list = '';
$cat_names = array();

foreach((array)$categories as $category)
$cat_names[] = sanitize_term_field('name', $category->name, $category->term_id, $tax, 'rss');
$cat_descriptions[] = sanitize_term_field('description', $category->description, $category->term_id, $tax, 'rss');

$cat_names = array_unique($cat_names);
$cat_descriptions = array_unique($cat_descriptions);

foreach($cat_names as $cat_name)
$the_list .= "\t\t<category domain=\"". $tax ."\"><![CDATA[" . @html_entity_decode($cat_name, ENT_COMPAT, get_option('blog_charset') ) . "]]></category>\n";

foreach($cat_descriptions as $cat_description)
$the_list .= "\t\t<wpq:category_description domain=\"". $tax ."\"><![CDATA[". @html_entity_decode($cat_description, ENT_COMPAT, get_option('blog_charset')) ."]]></wpq:category_description>\n";

return $the_list_original.$the_list;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.