lundi 29 décembre 2014

Translate SQL query to wp_database with JOINS into wp_query


StackExchange members!


It's so happened that I'm using straight SQL queries in my application. I'd like to rewrite it and use WP_Query, but, unfortunately, I have no idea how to translate, let's say, LEFT JOIN's into WP_Query properties.


Here an exerpt:



SELECT DISTINCT wp_posts.post_title, wp_terms.name AS text FROM wp_posts
LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
LEFT JOIN wp_terms ON (wp_term_relationships.term_taxonomy_id = wp_terms.term_id)
LEFT JOIN wp_term_taxonomy ON (wp_terms.term_id = wp_term_taxonomy.term_id)
WHERE wp_posts.post_status = 'publish'
AND (wp_terms.name LIKE '%$search_param%')
AND wp_posts.post_type = 'post'
AND wp_term_taxonomy.taxonomy = 'post_tag'


Is it possible to adopt this request to WP_Query usage? Could you give me an example for my piece of code?


Thank you for help!





Aucun commentaire:

Enregistrer un commentaire