寻找回报所有这些元价值

时间:2015-05-04 作者:Gomes
<?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 ] ),
            );
        }
    }
}

结束

相关推荐

使用新的WP-Query()从循环中过滤后期格式;

嗨,我目前正在为我的博客构建一个主题。下面的代码指向最新的帖子(特色帖子)。因为这将有一个不同的风格比所有其他职位。然而我想过滤掉帖子格式:链接使用我在循环中定义的WP查询,因为它给我带来了更多的灵活性。我该怎么做呢? <?php $featured = new WP_Query(); $featured->query(\'showposts=1\'); ?> <?php while ($featured->have_post