我想根据宽度,样式,类型和完成在WordPress中创建搜索。我创建了一个自定义帖子类型来输入产品。并使用自定义字段为每个产品添加宽度,样式类型和完成。现在我已经编写了这段代码,但它不是过滤产品。
<?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>
答案 0 :(得分:1)
问题出现在我的代码中,我必须在像这样的元数组之前添加另一个数组
$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' => '=<'
)
)
));