第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在 WooCommerce 中使用 WC_Query 按作者 ID 獲取產(chǎn)品?

在 WooCommerce 中使用 WC_Query 按作者 ID 獲取產(chǎn)品?

PHP
繁花不似錦 2023-10-15 15:50:48
我嘗試使用 WooCommerce 中的 WC_Query 通過(guò)帖子作者 id 獲取產(chǎn)品,因此我嘗試包含一個(gè)新的自定義元密鑰 "_author",其中包含以下內(nèi)容:add_filter( 'woocommerce_product_data_store_cpt_get_products_query', 'handling_custom_meta_query_keys', 10, 3 );function handling_custom_meta_query_keys( $wp_query_args, $query_vars ) {    $meta_key = '_author';     if ( ! empty( $query_vars[$meta_key] ) ) {        $wp_query_args['meta_query'][] = array(            'key'     => $meta_key,            'value'   => esc_attr( $query_vars[$meta_key] ),            'operator' => '==',         );    }    return $wp_query_args;}然后我嘗試將它與以下內(nèi)容一起使用wc_get_products():$product_list = wc_get_products( array('_author' => get_current_user_id()) );但它返回空數(shù)組。任何想法?
查看完整描述

2 回答

?
富國(guó)滬深

TA貢獻(xiàn)1790條經(jīng)驗(yàn) 獲得超9個(gè)贊

您可以使用未記錄的參數(shù)“author”在 WC_Query 中簡(jiǎn)單地按作者 ID 獲取產(chǎn)品,如下所示:


$products = wc_get_products( array(

    'status'    => 'publish',

    'limit'     => -1,

    'author'    => get_current_user_id()

) );

你將得到一個(gè)WC_Product對(duì)象數(shù)組


查看完整回答
反對(duì) 回復(fù) 2023-10-15
?
FFIVE

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊

您可以像這樣使用自定義查詢


<?php


$authorID = get_the_author_meta('ID');


$args = array(

    'post_type' => 'product',

    'post_status' => 'publish'

    'posts_per_page' => 12,

    'product_cat' => 'pants'

    'author'    => $authorID

);


$loop = new WP_Query( $args );


?>        

<div class="author_products">

    <?php if ( $loop->have_posts() ) { ?>

        <ul class="author_pubproducts">

        <?php while ( $loop->have_posts() ) : $loop->the_post();

            woocommerce_get_template_part( 'content', 'product' );

        endwhile; ?>

        </ul>

        <?php

        } else {

            echo __( 'No products found', 'textdomain' );

        }

        wp_reset_postdata();

    ?>

希望能成功


查看完整回答
反對(duì) 回復(fù) 2023-10-15
  • 2 回答
  • 0 關(guān)注
  • 143 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)