我创建了一个自定义搜索,可以在其中显示字段(ACF字段)和分类法。但是,当我通过结合分类法和元字段进行搜索时,我没有得到结果。如果我搜索分类法或元字段,它会给出结果。如何使这两个条件一起工作?
这是我提到meta\\u query和tax\\u query的代码:-
<?php
if($_POST){
$_speciality = $_POST[\'speciality\'] != \'\' ? $_POST[\'speciality\'] : \'\';
$_students_last_name = $_POST[\'students_last_name\'] != \'\' ? $_POST[\'students_last_name\'] : \'\';
if($_speciality!=" "){
$param1 = array(
\'key\' => \'speciality\',
\'compare\' => \'=\',
\'value\' => $_speciality
);
} else{
$param1 = "";
}
if($_students_last_name!=" "){
$param2=array(
\'key\' => \'students_last_name\',
\'compare\' => \'LIKE\',
\'value\' => $_students_last_name
);
} else{
$param2="";
}
$args = array(
\'post_type\' => \'students\',
\'orderby\' => \'date\',
\'order\' => \'DESC\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'Music\',
\'field\' => \'slug\',
\'terms\' => $param1
)
),
\'meta_query\' => array(
\'relation\' => \'AND\',
$param2
),
);
} else {
$args = array(
\'post_type\' => \'students\',
\'orderby\' => \'date\',
\'order\' => \'DESC\'
);
}
$the_query = new WP_Query( $args );