设置meta\\u查询值时,如:
\'value\' => "\'" . $city . "\'",
它被转换为
LIKE \'%\\\'ondon\\\'%\'
在最后的SQL查询中
L\'ondon\'
或
L\'ondon\'er
但不是
London
.
但实际上你希望它是这样的:LIKE \'%ondon%\'
- 因此,您应该:
\'value\' => $city,
EDIT
抱歉,我没有注意到这实际上是与Job Manager插件相关的
job_listing_region
是一种分类法。在这种情况下,您应该尝试执行以下操作:
// get taxonomy id\'s with names matching the query string $city
$foo_terms = get_terms( \'job_listing_region\', array(\'name__like\' => $city) );
$term_ids = [];
if ($foo_terms) {
foreach ($foo_terms as $foo_term) {
$term_ids[] = $foo_term->term_id;
}
}
// get jobs_listing entries matching retrieved id\'s
$args = array(
\'post_type\' => \'job_listing\',
\'post_status\' => \'publish\',
\'posts_per_page\' => -1,
\'tax_query\' => array(
array(
\'taxonomy\' => \'job_listing_region\',
\'field\' => \'term_id\',
\'terms\' => $term_ids,
\'operator\' => \'IN\'
)
)
);