How to retrieve specific information within this array?

Asked

Viewed 64 times

-3

I made a query SQL in the Wordpress database that returned me all the information related to a request, but I need to store some variables of this information and do not know how to do.

The $pid returns the ID of the applications identified by post_type=shop-order on the table wp_posts. I made a foreach sending the $pid obtained for the table wp_postmeta in order to redeem all information of all orders.

Follows the code:

$sqlSelect = "SELECT * FROM wp_posts WHERE post_type = 'shop_order'";

$pid = array();
foreach ($wpdb->get_results($sqlSelect) as $ids) {
    $pid[] .= $ids->ID;
}

foreach ($pid as $uid) {
    $sqlCompr = "SELECT * FROM wp_postmeta WHERE post_id = '$uid'";
    foreach ($wpdb->get_results($sqlCompr) as $infos) {
        echo $infos->meta_key .' - '. $infos->meta_value . "<br>";
    }
    echo "<br>";
}

This code returns me the following values:

inserir a descrição da imagem aqui

How I can store in a variable for example the value of ZIP CODE, guy ...

$cep = meta_value['_billing_postcode'] // output -> 79037-090;
  • Inside the foreach has already tested to do this? $wpdb->get_results($sqlCompr)['_billing_postcode'] ?

1 answer

0

If ($infos->meta_key=="_billing_postcode")$cep=$infos->meta_value;

That within the foreach

;)

  • 2

    Can you explain why this line of code helps solve the problem? So the answer is complete.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.