Woocommerce 当我在我的主题选项中添加产品名称列表作为下拉列表时

Woocommerce 当我在我的主题选项中添加产品名称列表作为下拉列表时,woocommerce,Woocommerce,我想在下拉列表中添加所有产品列表。 所以我添加了下面的代码来获得它 函数aaa(){ } 然后,我调用construct类中的函数。 但是我收到了错误信息,比如 “注意:试图在第1335行的/var/www/html/pro/style outlet/wp content/plugins/woocommerce/includes/data stores/class-wc-product-data-store-cpt.php中获取非对象的属性” 你能帮我解决这个问题吗?替换下面的行--- 用这个-

我想在下拉列表中添加所有产品列表。 所以我添加了下面的代码来获得它

函数aaa(){

}

然后,我调用construct类中的函数。 但是我收到了错误信息,比如

“注意:试图在第1335行的/var/www/html/pro/style outlet/wp content/plugins/woocommerce/includes/data stores/class-wc-product-data-store-cpt.php中获取非对象的属性”


你能帮我解决这个问题吗?

替换下面的行---

用这个---


你好,爱丽丝,谢谢你的密码。但它不起作用。尽管如此,我还是收到了错误消息。糟糕的是,使用get_the_id()作为get_the_title()函数的参数
$sliders = array();
$args    = array(
    'post_type'     => 'product',
    'posts_per_page' =>'-1',
);
$query   = new WP_Query( $args );
if ( $query->have_posts() ) {   
    while ( $query->have_posts() ) {
        $query->the_post();
        $sliders[ $query->post->ID ] = $query->post->post_title;
    }
}


return $sliders;
 $sliders[ $query->post->ID ] = $query->post->post_title;
$sliders[ get_the_id() ] = get_the_title();