SQL list of WordPress posts and categories

Ever wanted a listing of all your posts along with which categories they are in?  Want it in SQL outside of WordPress?  Then use this code  -

select wpr.object_id, wp_terms.name from wp_terms
inner join wp_term_taxonomy on wp_terms.term_id =
wp_term_taxonomy.term_id
inner join wp_term_relationships wpr on wpr.term_taxonomy_id =
wp_term_taxonomy.term_taxonomy_id
where taxonomy= "category"
order by object_id;

Or for a more expansive version with better clarity -

select p.post_title, wpr.object_id, wp_terms.name
from wp_terms
inner join wp_term_taxonomy on wp_terms.term_id =
wp_term_taxonomy.term_id
inner join wp_term_relationships wpr on wpr.term_taxonomy_id =
wp_term_taxonomy.term_taxonomy_id
inner join wp_posts p on p.ID = wpr.object_id
where taxonomy= "category" and p.post_type = 'post'
order by object_id;

There you have it. Point that through your favourite sql code runner, and be amazed by the results…

This entry was posted in Blog, Web and Tech, WordPress and tagged with .
Bookmark the permalink.
You can follow any comments here with the RSS feed for this post.
Both comments and trackbacks are currently closed.

There are 5 comments on this entry -

  1. markval
    Posted January 25, 2009 at 8:27 pm | Permalink

    Thanks,

    For all the inputs on the WP forum. I’ll post you the results once the 3D layers are populate from the cms.

  2. markval
    Posted January 26, 2009 at 2:20 am | Permalink

    Arg..

    Im stuck in a new problem with search form phpMyAdmin

    http://wordpress.org/support/topic/237497

    Any idea?

  3. markval
    Posted January 26, 2009 at 10:52 pm | Permalink

    Hi,

    Ive made a workaround.
    http://wordpress.org/support/topic/237497

    cheers!

  4. konya web tasarım
    Posted January 30, 2009 at 10:55 pm | Permalink

    For all the inputs on the WP forum. I’ll post you the results once

  5. Posted January 31, 2009 at 3:32 pm | Permalink

    this is real comment and thanks for all things