Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WP查询和多密钥_Php_Wordpress_Advanced Custom Fields - Fatal编程技术网

Php WP查询和多密钥

Php WP查询和多密钥,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我试图在我的wordpress中实现一个多元键过滤器。这很简单,我得到一个表单的值来过滤我的帖子。如果我只使用“price”查询来实现这一点,那么这个查询的措辞就非常完美了。如果我添加了“流派”无效,则查询无效 对于字段“类型”,我使用高级自定义字段中的复选框,其结构为“homme:homme/femme:femme” 我测试了不同的东西,比如删除“价格”和查询“类型”都不起作用 我从中得到了价值 <?php if($_GET['minprice'] && !

我试图在我的wordpress中实现一个多元键过滤器。这很简单,我得到一个表单的值来过滤我的帖子。如果我只使用“price”查询来实现这一点,那么这个查询的措辞就非常完美了。如果我添加了“流派”无效,则查询无效

对于字段“类型”,我使用高级自定义字段中的复选框,其结构为“homme:homme/femme:femme”

我测试了不同的东西,比如删除“价格”和查询“类型”都不起作用

我从中得到了价值

  <?php
     if($_GET['minprice'] && !empty($_GET['minprice']))
        {
            $minprice = $_GET['minprice'];
        } else {
            $minprice = 0;
        }

        if($_GET['maxprice'] && !empty($_GET['maxprice']))
        {
            $maxprice = $_GET['maxprice'];
        } else {
            $maxprice = 1000;
        }

 if($_GET['genre'] && !empty($_GET['genre']))
        {
            $genre = $_GET['genre'];
        }
    ?>
我的循环和我的查询

    <?php
  // set up or arguments for our custom query
  $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
  $args = array(
    'cat' => $cat,
    'post_type' => 'post',
    'posts_per_page' => 28,
    'paged' => $paged,
    'meta_query' => array(
        'relation' => 'AND',

            array(
                'key' => 'prix',
                'type' => 'NUMERIC',
                'value' => array($minprice, $maxprice),
                'compare' => 'BETWEEN'
                ), 

            array(
                'key' => 'genre',
                'value' => $genre,
                'compare' => 'LIKE'
                )
            )
        );

// create a new instance of WP_Query
  $the_query = new WP_Query($args);
?>

<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); // run the loop ?>

  <?php
 get_template_part( 'content-category', get_post_format() );
 ?>


<?php endwhile; ?>

<?php if ($the_query->max_num_pages > 1) { // check if the max number of pages is greater than 1  ?>
  <div class="clearfix"></div>

<?php bootstrap_pagination();?>

<?php } ?>

<?php else: ?>
        <?php get_template_part( 'no-results', 'archive' ); ?>
  <?php endif; ?>
</div>  
<?php wp_reset_query(); ?>
但那不行

$args = array(
            'cat' => $cat,
            'post_type' => 'post',
            'posts_per_page' => 28,
            'paged' => $paged,
            'meta_query' => array(         
                array(
                        'key' => 'genre',
                        'value' => $genre,
                        'compare' => 'LIKE'
                        )
                    )
                );
求求你,你能帮帮我吗,因为我正在失去理智。。。。
谢谢

我认为您在
meta\u查询中缺少一个包装数组

$args = array(
   'cat'            => $cat,
   'post_type'      => 'post',
   'posts_per_page' => 28,
   'paged'          => $paged,
   'meta_query'     => array(
      array(
         'relation' => 'AND',
         array(
            'key'     => 'prix',
            'type'    => 'NUMERIC',
            'value'   => array( $minprice, $maxprice ),
            'compare' => 'BETWEEN'
         ), 
         array(
            'key'     => 'genre',
            'value'   => $genre,
            'compare' => 'LIKE'
         ),
      ),
   ),
);
$args = array(
            'cat' => $cat,
            'post_type' => 'post',
            'posts_per_page' => 28,
            'paged' => $paged,
            'meta_query' => array(         
                array(
                        'key' => 'genre',
                        'value' => $genre,
                        'compare' => 'LIKE'
                        )
                    )
                );
$args = array(
   'cat'            => $cat,
   'post_type'      => 'post',
   'posts_per_page' => 28,
   'paged'          => $paged,
   'meta_query'     => array(
      array(
         'relation' => 'AND',
         array(
            'key'     => 'prix',
            'type'    => 'NUMERIC',
            'value'   => array( $minprice, $maxprice ),
            'compare' => 'BETWEEN'
         ), 
         array(
            'key'     => 'genre',
            'value'   => $genre,
            'compare' => 'LIKE'
         ),
      ),
   ),
);