我在mysql数据库中有一个带有键“app\\u I\\u have”的元字段和值,如:a:3:{i:0;s:14:"mobile studio";i:1;s:12:"own studio";i:2;s:9:"makeup artist";}
现在,我想通过pre\\u get\\u posts挂钩查询帖子,如下所示:
add_action( \'pre_get_posts\', \'rt_tax_archive\' );
function rt_tax_archive($query) {
if (is_admin()) {
return; /* If we\'re in the admin panel - drop out */
}
global $wp_query;
//For searching
if ($query->is_main_query() && isset($_GET[\'ls\'])) {
$rt_field_id_i_have = $_GET[\'listing_i_have\'];
//Filter posts by what they have
if (isset($rt_field_id_i_have) &&
!empty($rt_field_id_i_have[0])) {
$meta_query[] = array(
\'key\'=>\'app_i_have\',
\'value\'=>$rt_field_id_i_have[0],
\'compare\'=>\'LIKE\',
);
}
$query->set(\'meta_query\', $meta_query);
}
}
这是可行的,但当我想筛选具有“own studio”等功能的人时\'compare\'=>\'LIKE\'
还向人们展示了一个“移动工作室”。我猜是因为“工作室”这个词在里面。在这种情况下,如何正确过滤帖子?谢谢