我试图以'sold'和'leased'的状态返回两个属性。我已经成功地返回了“已售出”或“租借”的属性,但两者都没有。
我已将以下内容添加到我的函数文件中:
// FILTER PROPERTIES BY STATUS //
function my_pre_get_posts( $query ) {
// do not modify queries in the admin
if( is_admin() ) {
return $query;
}
// only modify queries for 'event' post type
if( isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'properties' ) {
// allow the url to alter the query
if( isset($_GET['status']) ) {
$query->set('meta_key', 'status');
$query->set('meta_value', $_GET['status']);
}
}
// return
return $query;
}
add_action('pre_get_posts', 'my_pre_get_posts');
我用来成功退回'sold'或'leased'属性的url格式是:
http://www.example.com/properties/?status=leased
或
http://www.example.com/properties/?status=sold
我是否可以使用简单的网址格式来包含这两个值?我曾尝试过例如:
http://www.example.com/properties/?status=leased&status=sold
或者我需要先修改功能吗?