1

Is it possible to get an RSS / XML feed of all WordPress Categories and/or Tags?

I've searched the Codex, which was very helpful in giving examples on how to access specific, individual RSS feeds, but have not been able to find any source on how to display all Categories of a site.

Using examples from the Codex, specific Categories can be found with the following structure:

example.com/category/categoryname/feed

I'm looking for something along the lines of:

example.com/category/*/feed

OR

example.com/categories/feed

Any thoughts? Solutions? Suggestions?


EDIT: I'm not looking for a feed of posts, rather a feed of all actual categories or tags. Ideally, this feed would contain only the categories themselves, no specific post data. Using the categories in the feed, however, I'd be able to then gather posts as needed by looking at each of the categories specific RSS feeds.

An example of what I'm looking for would be a feed that returned the following list:

  • Category 1
  • Category 2
  • Category 3
  • Category 4

Iterating over that, when needed, could give me the posts for each.

6
  • What kind of category/tag info are you looking for? What about exporting .wxr files? Maybe you already got a sitemap.xml?
    – birgire
    Commented Jun 25, 2014 at 20:20
  • I dont think you will find a solution for this as a feed for all categories or tags would be the same thing in essence as just providing a feed for all your posts. Each post would be assigned to at least 1 category or have tags so this would include everything and just a normal feed would do this then...
    – Matt Royal
    Commented Jun 25, 2014 at 20:49
  • @MattRoyal I've updated the question to help clarify. I'm not looking for a feed of posts, but for the categories themselves. No post data is needed- a feed of nothing but the actual categories used would suffice. Commented Jun 26, 2014 at 13:35
  • @birgire I'm looking for the category / tag short name. Whichever info would then allow a call to: example.com/category/categoryname/feed I'll look into which sitemaps are available. Commented Jun 26, 2014 at 13:38
  • @user2242816 I added an answer with a demo plugin, that you can hopefully extend further to your needs.
    – birgire
    Commented Jun 26, 2014 at 15:49

1 Answer 1

1

Demo plugin for JSON export:

I'm not sure the RSS feed structure suits your needs, for example taxonomies and terms don't have any dates for the public date field. So here's an example how you can retrieve all the terms for a given taxonomy:

/** 
 * Plugin Name: WPSE - JSON export all terms for a given taxonomy. 
 * Plugin URI:  http://wordpress.stackexchange.com/a/151908/26350
 * Version:     0.0.1
 */ 

add_filter( 'query_vars', function( $qv ){
    $qv[] = 'wpse-export-taxonomy';
    return $qv;
});

add_action( 'template_redirect', function(){

    $tax = get_query_var( 'export-taxonomy' );

    if( ! empty( $tax ) )
    {
        if( taxonomy_exists( $tax ) )
        {
            $data = get_terms( sanitize_key( $tax ), 
                array( 
                    'hide_empty' => true,
                    'orderby'    => 'name', 
                    'order'      => 'ASC', 
                ) 
            );

            if( count( $data ) > 0 )
                wp_send_json_success( $data );
        }
    }

    // Error:
    wp_send_json_error();

} );

where you can modiy the get_terms() arguments to your needs.

Usage Examples:

Categories export:

http://example.com/?wpse-export-taxonomy=category

Post tags export:

http://example.com/?wpse-export-taxonomy=post_tag

Custom country taxonomy export:

http://example.com/?wpse-export-taxonomy=country

The category export could look like this:

{"success":true,"data":{
"0":{"term_id":"65","name":"animals","slug":"animals","term_group":"0","term_taxonomy_id":"75","taxonomy":"category","description":"id:65","parent":"0","count":"5"},
"1":{"term_id":"61","name":"birds","slug":"birds","term_group":"0","term_taxonomy_id":"70","taxonomy":"category","description":"id:61","parent":"65","count":"8"}
"2":{"term_id":"13","name":"falcons","slug":"falcons","term_group":"0","term_taxonomy_id":"15","taxonomy":"category","description":"id:13","parent":"61","count":"3"}
}}

I hope this helps.

2
  • Apologies for the incredibly late acceptance of this answer! While I'd been looking for an example using Wordpress's default RSS feeds (I didn't have control of actual WP instance), this is still a great solution for my question. Thank you! Commented Mar 2, 2015 at 14:08
  • you're welcome and thanks for reporting back @user2242816
    – birgire
    Commented Mar 2, 2015 at 14:18

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.