再次感谢 Dinesh - 最终到达那里 - 结果如下
WP 模板是一回事 - 对此感到满意 - 只是对 Woocommerce 有点困惑。
最终结果:
由于 Woocommerce 搜索结果被输入到他们的插件特定的“archive-product.php”页面中,我不得不在那里添加你的代码。 archive-pruduct.php 也是主要类别列表页面,因此在使用上述覆盖之前需要使用 is_search 条件捕获搜索:
我是这样做的:
<?php
if ( is_search() ) :
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'order' => 'ASC',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'meta:_isbn_field', //your meta key
'value' => $_REQUEST['meta:_isbn_field'], //your search post value
'compare' => 'LIKE'
)
), array(
'key' => 'meta:_published_field', //your meta key
'value' => $_REQUEST['meta:_published_field'], //your search post value
'compare' => 'LIKE'
),
array(
'key' => 'meta:_publisher_field', //your meta key
'value' => $_REQUEST['meta:_publisher_field'], // your search post value for author
'compare' => 'LIKE'
),
array(
'key' => 'post_title',
'value' => $_REQUEST['post_title'],
'compare' => 'LIKE'
)
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
echo '<h2>Your search Results</h2>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo wc_get_template_part( 'content', 'single-productsimple' );
}
}else{
echo 'sorry nothing found';
}
else:
//leave default archive-product.php code here
endif;
?>