Hello.
I need help from anyone who understands MYSQL queries well.
I have 5k posts, each post have category assigned.
Each category have have order - "wp_terms" have additional field "menu_order", using plugin: "Term Menu Order".
Each post is tagged also, by one tag, no more, no less.
I want to list Posts and group them by Category order.
Also I want to use pagination, i will use offset and limit for that.
I conjured a MYSQL query, taken out from wordpress, that is not doing the job right.
SELECT wp_posts.*, wp_terms.term_order
FROM wp_posts
INNER
JOIN wp_term_relationships
ON (wp_posts.ID = wp_term_relationships.object_id)
INNER
JOIN wp_term_relationships AS tt1
ON (wp_posts.ID = tt1.object_id)
INNER
JOIN wp_terms
ON (wp_terms.term_id = wp_term_relationships.term_taxonomy_id)
WHERE 1=1
AND (
wp_term_relationships.term_taxonomy_id IN (36,38,40,42,44,46) //cat, single or multiple
AND tt1.term_taxonomy_id IN (20) //tag, single or multiple
)
AND wp_posts.post_type = 'post'
AND (
wp_posts.post_status = 'publish'
OR wp_posts.post_status = 'private'
)
ORDER BY wp_terms.term_order ASC //order by category order.
LIMIT 0, 10
I hope I made some-clear picture of what I want to achieve, thanks :)