Custom WP query with polylang term
Question
i am banging my head on how should the mysql query be correctly defined.
I have term_taxonomy_id id defined for polylang languages 2 and 9
I want to return ONLY return posts, who has term_taxonomy_id 2 (primary language) AND then from the result all posts who has term_taxonomy_id 32,71,38.
Can you help me on this? Where i am wrong on this query?
SELECT SQL_CALC_FOUND_ROWS
agn_posts.ID,
agn_posts.post_title,
agn_term_relationships.term_taxonomy_id
FROM
agn_posts
LEFT JOIN agn_term_relationships ON(
agn_posts.ID = agn_term_relationships.object_id
)
WHERE
1 = 1
AND(
agn_term_relationships.term_taxonomy_id IN(32)
OR agn_term_relationships.term_taxonomy_id IN(71)
OR agn_term_relationships.term_taxonomy_id IN(38)
)
AND agn_term_relationships.term_taxonomy_id IN(2)
AND agn_posts.post_type = 'property' AND(
agn_posts.post_status = 'publish' OR agn_posts.post_status = 'private'
)
GROUP BY
agn_posts.ID
ORDER BY
RAND()
LIMIT 0, 50
0
3 months
0 Answers
12 views
0
Leave an answer
You must login or register to add a new answer .