Getting an array out of WPQuery

Your function returns $product->get_id();, instead of that, you should save those values into an array and at the end return that array.

function ids(){
    $args = array(
        'numberposts'   => -1,
        'post_type'     => 'product',
        'meta_key'      => 'wppl_is_dax',
        'meta_value'    => '1'
    );


    // query
    $the_query = new WP_Query( $args );
    $allIds = array();

            if( $the_query->have_posts() ): while( $the_query->have_posts() ) : $the_query->the_post();
                global $product;
                array_push($allIds,$product->get_id());
                endwhile; endif; wp_reset_query();
    return $allIds;
}

Leave a Comment