Site icon Hip-Hop Website Design and Development

Time period and sub time period from customized submit sort question [closed]

I’ve created a customized submit sort and taxonomy for a items catalogue for a rent web site. This works high quality. I’m attempting to generate a report that lists all gadgets and their class and sub class. I got here up with this to generate a desk with the primary class:

SELECT 
wp_posts.ID as ID, 
wp_posts.post_title as post_title,
wp_terms.title as main_category,
wp_terms.term_id as main_category_id
FROM 
wp_posts, wp_term_relationships, wp_terms, wp_term_taxonomy
WHERE
wp_term_relationships.object_id = wp_posts.ID
AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id 
AND wp_term_taxonomy.term_id = wp_terms.term_id
AND wp_term_taxonomy.father or mother = '0'
AND wp_posts.post_type = 'items' 
AND wp_posts.post_status = 'publish'
ORDER BY wp_terms.term_id ASC

I simply loop by and its high quality. However I wish to present the sub class too – which I can do by placing one other question within the foreach php loop.

BUT, I must order by principal class after which sub class.

So I figured I would like it multi function question. And it have to be doable. I’ve tried experimenting with JOINing tables within the question however cannot get the syntax proper. Heres the newest one I attempted.

SELECT 
wp_posts.ID as ID, 
wp_posts.post_title as post_title,
s1.title as main_category,
s1.term_id as main_category_id,
s2.title as main_category,
s2.term_id as main_category_id
FROM 
wp_posts, wp_term_relationships, wp_terms s1, wp_term_taxonomy
LEFT JOIN wp_terms s2
ON s1.term_id = s2.id
WHERE
wp_term_relationships.object_id = wp_posts.ID
AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id 
AND wp_term_taxonomy.term_id = s1.term_id
AND wp_term_taxonomy.father or mother = '0'
AND wp_posts.post_type = 'items' 
AND wp_posts.post_status = 'publish'
ORDER BY s1.term_id ASC