WPML - SQL query to get post by current language

Viewed 38

I'm using WPML and need a custom search query (The default search of wordpress is not working in my case). Let say my query is: "SELECT * FROM wp_posts WHERE post_title LIKE %s% AND [WPML_CURRENT_LANGUAGE_CONDITION]";

Please help me check which table I should care for this.

Thanks!

1 Answers

After checking with my friend, he helped me out and this query is find post in current language only.

$sql = "SELECT * FROM wp_posts
INNER JOIN wp_icl_translations post_trans
ON wp_posts.ID = post_trans.element_id
WHERE [...YOUR CONDITIONS]
AND post_trans.language_code = '". ICL_LANGUAGE_CODE ."'";
Related