I want to add all product lists in dropdown.
So I added the below code to get it.

function aaa() {

$sliders = array();
$args    = array(
    'post_type'     => 'product',
    'posts_per_page' =>'-1',
$query   = new WP_Query( $args );
if ( $query->have_posts() ) {   
    while ( $query->have_posts() ) {
        $sliders[ $query->post->ID ] = $query->post->post_title;

return $sliders;


And then, I call the function within construct class.
But I get the error message, like

“Notice: Trying to get property of non-object in /var/www/html/pro/style-outlet/wp-content/plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php on line 1335”

Can you please help me with this??

Read more here: When I added product Name lists as a DropDown in my theme option


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: