Generating a perfect loop

So I have been sitting here now for about three hours and I have to let this go for a few hours to grab some sleep while I hopefully get some help from you.

I have been able to get content from a database using $wpdb->get_results, and have been able to put them into an array, but I then want to use that information to run a new query inside a loop to fetch multiple items in a list.

I have used a variation of this guide https://stackoverflow.com/questions/45848249/woocommerce-get-all-orders-for-a-product to get the order ids. Now that I have them in an array, I would like to loop the array without getting a duplicate first entry. This is my current code that works, but it gives a duplicate first entry.

foreach ($orders_ids as $details) {
$paameldingid[]=$details->order_id;
$i=0;
while ($order_id = $paameldingid[$i]){
$order = wc_get_order($order_id);
$fornavn = $order->get_billing_first_name();
$etternavn = $order->get_billing_last_name();
$deltakerkategori = $order->get_meta( ‘_billing_field_447’, true );
$deltakerradio = $order->get_meta( ‘_billing_field_538′, true );
echo ”.$fornavn.’ ‘.$etternavn.’ ‘.$deltakerkategori.’/’.$deltakerradio.'<br>’;
$i++;
}
}

Working example: http://www.va24.no/paameldinger.php

Read more here:: Generating a perfect loop

Leave a Reply

Your email address will not be published. Required fields are marked *