get_the_category_rss

Retrieve all of the post categories, formatted for use in feeds.

Description

(string) get_the_category_rss( (constant) $type = null ); 

All of the categories for the current post in the feed loop, will be retrieved and have feed markup added, so that they can easily be added to the RSS2, Atom, or RSS1 and RSS0.91 RDF feeds.

Returns (string)

All of the post categories for displaying in the feed.

Parameters (1)

0. $type — Optional. (constant) => null
Optional, default is the type returned by get_default_feed().

Usage

  1. if ( !function_exists( 'get_the_category_rss' ) ) { 
  2. require_once ABSPATH . WPINC . '/feed.php'; 
  3.  
  4. // Optional, default is the type returned by get_default_feed(). 
  5. $type = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_the_category_rss($type); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/feed.php  
  1. function get_the_category_rss($type = null) { 
  2. if ( empty($type) ) 
  3. $type = get_default_feed(); 
  4. $categories = get_the_category(); 
  5. $tags = get_the_tags(); 
  6. $the_list = ''; 
  7. $cat_names = array(); 
  8.  
  9. $filter = 'rss'; 
  10. if ( 'atom' == $type ) 
  11. $filter = 'raw'; 
  12.  
  13. if ( !empty($categories) ) foreach ( (array) $categories as $category ) { 
  14. $cat_names[] = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter); 
  15.  
  16. if ( !empty($tags) ) foreach ( (array) $tags as $tag ) { 
  17. $cat_names[] = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter); 
  18.  
  19. $cat_names = array_unique($cat_names); 
  20.  
  21. foreach ( $cat_names as $cat_name ) { 
  22. if ( 'rdf' == $type ) 
  23. $the_list .= "\t\t<dc:subject><![CDATA[$cat_name]]></dc:subject>\n"; 
  24. elseif ( 'atom' == $type ) 
  25. $the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', esc_attr( get_bloginfo_rss( 'url' ) ), esc_attr( $cat_name ) ); 
  26. else 
  27. $the_list .= "\t\t<category><![CDATA[" . @html_entity_decode( $cat_name, ENT_COMPAT, get_option('blog_charset') ) . "]]></category>\n"; 
  28.  
  29. /** 
  30. * Filters all of the post categories for display in a feed. 
  31. * @since 1.2.0 
  32. * @param string $the_list All of the RSS post categories. 
  33. * @param string $type Type of feed. Possible values include 'rss2', 'atom'. 
  34. * Default 'rss2'. 
  35. */ 
  36. return apply_filters( 'the_category_rss', $the_list, $type );