gpt4 book ai didi

php - Woocommerce - 使用特定属性列出产品

转载 作者:行者123 更新时间:2023-11-29 12:07:40 25 4
gpt4 key购买 nike

我正在尝试进行自定义查询来获取具有“League = NCAA”的产品,如图所示。我总共有 74 个ncaa 联赛

http://i.stack.imgur.com/MQDAL.png

现在我的查询是这样的,但它什么也没显示。

<ul class="products grid ncaa">
<?php
$args = array(
'post_type' => 'product',
'meta_key' => 'league',
'meta_value' => 'ncaa',
'posts_per_page' => 12

);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( 'content', 'product' );
endwhile;
} else {
woocommerce_get_template( 'loop/no-products-found.php' );
}

?>
</ul>

从数据库中搜索关键字“NCAA”后,它向我显示了此表,但我不知道如何从这里获取:-

http://i.stack.imgur.com/kjK17.png

查看表格后,我尝试进行此查询,它仅在前端显示单个产品,但我想显示包含产品的所有 ncaa 属性。

 <ul class="products grid ncaa">
<?php
$args = array(
'post_type' => 'product',
'meta_key' => '_product_attributes',
'meta_value' => 'a:2:{s:6:"league";a:6:{s:4:"name";s:6:"League";s:5:"value";s:4:"NCAA";s:11:"is_taxonomy";i:0;s:8:"position";i:0;s:10:"is_visible";i:1;s:12:"is_variation";i:0;}s:3:"upc";a:6:{s:4:"name";s:3:"UPC";s:5:"value";s:12:"889345125070";s:11:"is_taxonomy";i:0;s:8:"position";i:0;s:10:"is_visible";i:1;s:12:"is_variation";i:0;}}',
'posts_per_page' => 12

);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( 'content', 'product' );
endwhile;
} else {
woocommerce_get_template( 'loop/no-products-found.php' );
}

?>
</ul>

最佳答案

我刚刚这样做了,它就像一个魅力:-)

 <ul class="products grid ncaa">
<?php
$args = array(
//'meta_compare' => 'LIKE',
'post_type' => 'product',
'posts_per_page' => '74',
'meta_query' => array(
array(
'key' => '_product_attributes',
'value' => 'ncaa',
'compare' => 'LIKE',
'type' => 'ncaa'
)
)
);
$loop = new WP_Query( $args );

if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
{
wc_get_template_part( 'content', 'product' );
}
endwhile;
} else {
woocommerce_get_template( 'loop/no-products-found.php' );
}
?>
</ul>

关于php - Woocommerce - 使用特定属性列出产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31199097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com