Wordpress Database SQL query help needed

Posted by i-CONICA on Stack Overflow See other posts from Stack Overflow or by i-CONICA
Published on 2010-06-18T08:57:34Z Indexed on 2010/06/18 9:03 UTC
Read the original article Hit count: 266

Filed under:
|
|

Hi,

I've written a PHP script to access the latest item from the wordpress database, which it does. But I need to use it twice, once for the latest item from a specific category, and another from a differerent category...

But right now I cannot figure out how to put the query together.

The post has a post_parent, which in another table, called wp_term_relationships, is referred to as object_id, and has a term_taxonomy_id, which then relates to a different table, called wp_terms where the term_taxonomy_id is now term_id and then you have the category slug name available to select...

I really cannot understand how this query would work though.

I've made a really crap mock up of it, to try to "visually" explain what i'm trying to do...

SELECT * FROM wp_posts WHERE post_status = 'publish' AND (SELECT term_taxonomy_id FROM wp_term_relationships WHERE object_id = post_parent) AND (SELECT slug FROM wp_terms WHERE term_id = term_taxonomy_id) ORDER BY ID DESC LIMIT 1

Really would appreciate some help... Thanks.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about database