<?php
if(isset($_REQUEST[\'src\'])):
$business = $_REQUEST[\'srcbusiness\'];
$type = $_REQUEST[\'srctype\'];
$price = $_REQUEST[\'srcprice\'];
$city = $_REQUEST[\'srccity\'];
$district = $_REQUEST[\'srcdistrict\'];
$query = (array(\'post_type\'=>\'post\',\'category_name\'=>$business,\'meta_value\'=>$type,\'meta_value\'=>$price,\'meta_value\'=>$city,\'meta_value\'=>$district));
endif;
?>
寻找回报所有这些元价值
1 个回复
最合适的回答,由SO网友:TheDeadMedic 整理而成
您需要使用meta query:
if ( isset( $_REQUEST[\'src\'] ) ) {
$query = array(
\'post_type\' => \'post\',
\'meta_query\' => array(
),
);
if ( isset( $_REQUEST[\'srcbusiness\'] ) ) {
$query[\'category_name\'] = wp_unslash( $_REQUEST[\'srcbusiness\'] );
}
$fields = array(
\'srctype\',
\'srcprice\',
\'srccity\',
\'srcdistrict\',
);
foreach ( $fields as $field ) {
if ( isset( $_REQUEST[ $field ] ) ) {
$meta_query[] = array(
\'key\' => $field,
\'value\' => wp_unslash( $_REQUEST[ $field ] ),
);
}
}
}
结束