admin管理员组文章数量:1278984
i am new to wp and I tried to filter product inside archive-product.php woocommerce shop page by using product meta key and value but unable to do that. Wordpress version i am using 5.8.1 and woocommerce version 5.5.2 . I also tried it by adding acf field in product post but still no response. here's the code that i tried
$q->set('meta_query', [
[
'key' => 'meta_key', // used target meta key
'value' => 'meta_value', // dynamic variable
'compare' => '=' // also used LIKE in compare
]
]);
here is how i am using this code inside functions.php (child theme)file
function so_20990199_product_query( $q ){
if (isset($_GET['filterbyAge'])) {
$q->set('meta_query', [
[
'key' => 'book_age_group',
'value' => $_GET['filterbyAge'],
'compare' => '='
]
]);
}
}
add_action( 'woocommerce_product_query', 'so_20990199_product_query' );
本文标签: woocommerce offtopicunable to customize query to get filtered products by metakey
版权声明:本文标题:woocommerce offtopic - unable to customize query to get filtered products by meta_key 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741252071a2365980.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论