我创建了一个包含多个字段的搜索表单,我想显示与搜索表单中插入的所有字段相匹配的帖子。
例如,如果我选择T恤&&;红色(&A)&;五十、 我把所有贴子的T恤作为meta\\u值T恤,所有贴子的红色作为meta\\u值,所有贴子的L作为meta\\u值。
代码如下:
<?php if ( ($_GET[\'product_color\'] == \'empty\') && ($_GET[\'product_size\'] == \'empty\') && ($_GET[\'product_type\'] == \'empty\') ) { ?>
<h1 class="pagetitle">No Results!</h1>
<?php } else {
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
// WP_Query arguments
$args = array (
\'post_type\' => \'custom_products\',
\'post_status\' => \'published\',
\'pagination\' => true,
\'posts_per_page\' => 20,
\'order\' => \'DESC\',
\'orderby\' => \'parent\',
\'paged\' => $paged,
\'suppress_filters\' => false,
\'meta_query\' => array(
\'relation\' => \'OR\',
array(
\'key\' => \'product_color\',
\'value\' => $product_color,
\'compare\' => \'LIKE\'
),
array(
\'key\' => \'product_size\',
\'value\' => $product_size,
\'compare\' => \'LIKE\'
),
array(
\'key\' => \'product_type\',
\'value\' => $product_type,
\'compare\' => \'LIKE\'
),
),
);
// The Query
$searched_posts = new WP_Query( $args );
如何修改查询以实现目标?
提前感谢您!