我有以下内容来创建分类标准的搜索表单,来自"考试"自定义帖子类型。
我想做的是扩展搜索范围以包含名称为" examination_code"的字段。来自"考试"自定义帖子类型。
function buildSelect($tax){
$terms = get_terms($tax);
$x = '<select multiple="multiple" name="'. $tax .'[]">';
$x .= '<option value="">Select '. ucfirst($tax) .'</option>';
foreach ($terms as $term) {
$x .= '<option value="' . $term->slug . '">' . $term->name . '</option>';
}
$x .= '</select>';
return $x;
}
搜索表单:
<form method="post" action="<?php bloginfo('url'); ?>/timetable-results/">
<?php
$taxonomies = get_object_taxonomies('exam');
$taxonomies = array_diff($taxonomies, ["language", "post_translations"]);
foreach($taxonomies as $tax){
echo buildSelect($tax);
}
?>
<input type="submit"/>
</form>
结果页面:
<?php
$tax_query = array();
foreach ( get_object_taxonomies( 'exam' ) as $tax ) {
if ( isset( $_POST[ $tax ] ) ) {
$tax_query[] = array(
'taxonomy' => $tax,
'terms' => wp_unslash( ( array ) $_POST[ $tax ] ),
'field' => 'slug',
);
}
}
$args['tax_query'] = $tax_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args['paged'] = $paged;
$the_query = new WP_Query( $args );
var_dump($the_query);
?>