久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

WooCommerce 通過(guò)屬性查詢(xún)獲取產(chǎn)品

WooCommerce get products by attribute query(WooCommerce 通過(guò)屬性查詢(xún)獲取產(chǎn)品)
本文介紹了WooCommerce 通過(guò)屬性查詢(xún)獲取產(chǎn)品的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

我有一個(gè)帶有屬性顏色的產(chǎn)品.屬性值為紅色、藍(lán)色和綠色.我正在嘗試創(chuàng)建自定義搜索,但無(wú)法通過(guò)查詢(xún)提取任何產(chǎn)品.

I have a product with attribute colors. Attribute values are red, blue and green. I am trying to create a custom search but I can't get the query to pull any product.

$args =  array(
    'post_type'      => array('product'),
    'post_status'    => 'publish',
    'posts_per_page' => -1,
    'meta_query'     => array( 
        array(
            'key' => '_visibility',
            'value' => array('catalog', 'visible'),
            'compare' => 'IN',  
        ) 
    ),
    'tax_query'      => array( 
        array(
            'taxonomy'        => 'product',
            'field'           => 'slug',
            'terms'           =>  array('blue', 'red', 'green'),
            'operator'        => 'IN',
        ),
    )
);

$products = new WP_Query( $args );

我哪里做錯(cuò)了?

推薦答案

產(chǎn)品屬性顏色的正確分類(lèi)是 'pa_color',所以正確的工作查詢(xún)是:

The correct taxonomy for the product attribute color is 'pa_color', so the correct working query is:

// The query
$products = new WP_Query( array(
   'post_type'      => array('product'),
   'post_status'    => 'publish',
   'posts_per_page' => -1,
   'meta_query'     => array( array(
        'key' => '_visibility',
        'value' => array('catalog', 'visible'),
        'compare' => 'IN',
    ) ),
   'tax_query'      => array( array(
        'taxonomy'        => 'pa_color',
        'field'           => 'slug',
        'terms'           =>  array('blue', 'red', 'green'),
        'operator'        => 'IN',
    ) )
) );

// The Loop
if ( $products->have_posts() ): while ( $products->have_posts() ):
    $products->the_post();
    $product_ids[] = $products->post->ID;
endwhile;
    wp_reset_postdata();
endif;

// TEST: Output the Products IDs
print_r($product_ids);

此代碼已經(jīng)過(guò)測(cè)試并且可以正常工作.您將獲得所有具有顏色屬性的產(chǎn)品,其值(術(shù)語(yǔ))為藍(lán)色"、紅色"和綠色"……

This code is tested and works. You will get all products that have Color attribute with the values (terms) 'blue', 'red' and 'green'…

自 WooCommerce 3 起,產(chǎn)品可見(jiàn)性由自定義分類(lèi)法 product_visibility 處理.您可以看到以下相關(guān)主題:

Since WooCommerce 3, product visibility is handled by custom taxonomy product_visibility. You can see the following related threads:

  • woocommerce 3 中產(chǎn)品的數(shù)據(jù)庫(kù)更改
  • 在 Woocommerce 的 WP_query 中獲取目錄中可見(jiàn)的產(chǎn)品

這篇關(guān)于WooCommerce 通過(guò)屬性查詢(xún)獲取產(chǎn)品的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產(chǎn)品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產(chǎn)品的總訂單數(shù))
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗(yàn)證問(wèn)題中添加自定義注冊(cè)字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡(jiǎn)單產(chǎn)品中添加一個(gè)將更改價(jià)格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產(chǎn)品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結(jié)帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 国产在线97 | 7777精品伊人久久精品影视 | 亚洲欧美日韩国产综合 | 欧美色999| 伊人焦久影院 | 国产在线一区二区三区 | 亚洲精品成人 | 日韩有码一区 | 久久久国产精品 | 欧美性一区二区三区 | 亚洲区一区二区 | 一区天堂 | 国产精品视频www | 蜜桃视频在线观看免费视频网站www | 美女福利视频 | 亚洲国产精品久久久久婷婷老年 | 日韩电影一区 | 亚洲情视频 | 久草久草久草 | 一a一片一级一片啪啪 | 日本一区二区三区在线观看 | 天天躁日日躁狠狠的躁天龙影院 | 亚洲三级视频 | 久久国产婷婷国产香蕉 | 国产美女精品 | 中文字幕一区二区三区在线观看 | 欧美一级特黄aaa大片在线观看 | 精品日韩一区二区 | 欧美日韩国产一区二区三区 | 亚洲欧美中文日韩在线v日本 | 亚洲人成在线播放 | 精品免费国产一区二区三区四区 | 日韩成人精品在线 | 成人亚洲视频 | 特黄视频 | 欧美亚洲国产一区二区三区 | 麻豆精品一区二区三区在线观看 | 91精品久久久久久久久久 | 日韩日b视频 | 色爱区综合| 久久久久久久av麻豆果冻 |