WP_Query meta_query “Like” Returning results with words not related/listed

I have the below as part of a wp_query with meta_query to filter a group of results from a custom field called cpt_type. It “sort of” works with IN, but not at all with LIKE.

With LIKE, it is returning results that aren’t even close, like “2 Door Coupe” and “4 Door Sedan.” Neither of those strings has SUV or Sport Utility.

The problem with using IN is that it only matches EXACT. So, if the post has exactly SUV with nothing else, it returns. But, if a vehicle is listed as “4 Door SUV,” it isn’t returning. Hence why I am trying to use LIKE.

if ($_GET[‘type’] == “suv”) {
$typeterm = array( ‘SUV’, ‘Sport Utility’ );
$typekey = ‘cpt_type’;
$typecompare = ‘LIKE’;
}

Read more here:: WP_Query meta_query “Like” Returning results with words not related/listed

Leave a Reply

Your email address will not be published. Required fields are marked *