Select Posts within a Wordpress Category in MySQL
My SQL knowledge is fairly basic. I am an interactive designer, not a strict low-level coder, so I am looking for solutions that do not require cryptic or highly detailed SQL, when I want to access a DB system.
If you want to access the WP MySQL database tables, you can of course include the ‘wp-db.php’ file and use their class which is a wrapper (as detailed on the Wordpress.com site) for accessing the DB. I tried this, and within the system I am working on (PHP files pulling posts from a certain category on a WP install into a completely different site), this didn’t work for me.
Again my SQL is quite basic, but you should be able to see the table relationships based on my ‘kiddie code’.
Below is the code to pull in articles from a category:
SELECT DISTINCT post_name FROM `wp_posts`, wp_term_relationships, wp_term_taxonomy WHERE wp_term_relationships.object_id = wp_posts.id AND post_status = ‘publish’ and post_type = ‘post’ AND wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id AND wp_term_taxonomy.taxonomy = ‘category’ AND wp_term_taxonomy.term_id = YOUR_CATEGORY_ID




Comments(0)![[del.icio.us]](http://www.heaveninteractive.com/weblog/wp-content/plugins/bookmarkify/delicious.png)
![[Facebook]](http://www.heaveninteractive.com/weblog/wp-content/plugins/bookmarkify/facebook.png)
![[LinkedIn]](http://www.heaveninteractive.com/weblog/wp-content/plugins/bookmarkify/linkedin.png)
![[StumbleUpon]](http://www.heaveninteractive.com/weblog/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Twitter]](http://www.heaveninteractive.com/weblog/wp-content/plugins/bookmarkify/twitter.png)