创建自定义搜索

Create a Custom Search

我想在 WordPress 中根据宽度、样式、类型和完成创建搜索。我创建了一个自定义 post 类型来输入产品。并使用自定义字段为每个产品添加宽度、样式类型和饰面。现在我写了这段代码,但它没有过滤产品。

<?php
    $width=$_POST['width'];
    list($first, $secnd)=split('-', $width);
    $sink=$_POST['type'];
    $finish=$_POST['finish'];
    $style=$_POST['style'];
?>

<ul class="vanity-collection">
    <?php
        // Start the Loop.
        $query=new WP_Query(array('post_type'=>'products',
            'meta_query' => array(
                'key' => 'width',
                'value' => $first,
                'compare' => '>='
            ),
            array(
                'key' => 'width',
                'value' => $secnd,
                'compare' => '=<'
            ),
            array(
                'key' => 'sink-type',
                'value' => $sink,
                'compare' => '=<'
            ),
            array(
                'key' => 'finish',
                'value' => $finish,
                'compare' => '=<'
            ),
            array(
                'key' => 'style',
                'value' => $style,
                'compare' => '=<'
            )
        ));
        while ( $query->have_posts() ) : $query->the_post();
        $product_img=get_the_ID();
    ?>
    <li>
        <div class="img-box">
            <?php echo get_the_post_thumbnail( $product_img,array(291,202,true)); ?>
            <a href="#" class="hover-collection"></a>
        </div>
        <span class="font-collection-detail"><?php the_title(); ?></span>
    </li>
    <?php
        endwhile;
    ?>
</ul>

问题出在我的代码中,我必须像这样在元数组之前添加另一个数组

$query=new WP_Query(array('post_type'=>'products',
            'meta_query' => array(
array(
                'key' => 'width',
                'value' => $first,
                'compare' => '>='
            ),
            array(
                'key' => 'width',
                'value' => $secnd,
                'compare' => '=<'
            ),
            array(
                'key' => 'sink-type',
                'value' => $sink,
                'compare' => '=<'
            ),
            array(
                'key' => 'finish',
                'value' => $finish,
                'compare' => '=<'
            ),
            array(
                'key' => 'style',
                'value' => $style,
                'compare' => '=<'
            )
)
        ));