The get_the_category_rss() WordPress PHP function retrieves all of the post categories, formatted for use in feeds.
Usage
echo get_the_category_rss('rss2');
Parameters
$type
(string, optional) – The type of feed format. Default is the type returned byget_default_feed()
. Default: null.
More information
See WordPress Developer Resources: get_the_category_rss
Examples
Display categories in RSS2 format
Retrieve categories for the current post in the loop and display them in RSS2 format.
// Output categories in RSS2 format echo get_the_category_rss('rss2');
Display categories in Atom format
Retrieve categories for the current post in the loop and display them in Atom format.
// Output categories in Atom format echo get_the_category_rss('atom');
Display categories in RDF format
Retrieve categories for the current post in the loop and display them in RDF format.
// Output categories in RDF format echo get_the_category_rss('rdf');
Display categories in default feed format
Retrieve categories for the current post in the loop and display them in the default feed format.
// Output categories in default feed format echo get_the_category_rss();
Use within a custom RSS feed template
Create a custom RSS feed template and use get_the_category_rss()
to display categories in the desired feed format.
header('Content-Type: ' . feed_content_type('rss2') . '; charset=' . get_option('blog_charset'), true); echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '"?' . '>'; ?> <rss version="2.0"> <channel> <!-- ... --> <?php while (have_posts()) : the_post(); ?> <item> <!-- ... --> <category><?php echo get_the_category_rss('rss2'); ?></category> <!-- ... --> </item> <?php endwhile; ?> </channel> </rss>