Take this basic query:
$posts = new WP_Query(array( 'post_type' => 'page' 's' => 'some search query' ));
WordPress will split the
some search query into 3 separate search terms, which is why I need to make this $wpdb function. I want the same functionality, but with the entire query treated as 1 search term.
Here is where I'm at:
global $wpdb; $post_type = 'product'; $db_matches = $wpdb->get_results(" SELECT ID FROM $wpdb->posts INNER JOIN $wpdb->term_relationships ON $wpdb->term_relationships.object_id = $wpdb->posts.post_title WHERE post_title LIKE '%$query%' AND post_type = '$post_type' AND post_status = 'publish' ");
This is my first inner join ever, so it's probably all wrong. Two things need to be done to fix this query:
- Fix the syntax in the inner join line
- Add the language filter in the
WHEREclauses (should be something like
AND term_taxonomy_id = 2, right?). I'm using Polylang, so I just need to check that the
object_idexists in the
term_relationshipstable with the value
So can anyone give me a hand with this? Thanks a lot.