0

I need some help in getting single string from wpdb instead od array. The below code should return child post number. It will always return array with single element.

    global $wpdb;
$store = wp_get_current_user();
$store_id = $store->ID;
 $par_order = $reservation->transaction_id;
 $sql = "SELECT ID FROM " . $wpdb->prefix . "posts
         WHERE post_type = 'shop_order'
         AND post_parent = " . $par_order
        . " AND post_author = " . $storer_id;
 $sub_orders = $wpdb->get_results($sql);
6
  • 1
    Try get_var instead of get_results developer.wordpress.org/reference/classes/wpdb/get_var Oct 18, 2016 at 19:03
  • @czerspalace Unfortunetely it hasn't helped.
    – Rafal
    Oct 18, 2016 at 19:24
  • Is it still returning an array? Can you show your updated code with get_var? Oct 18, 2016 at 19:46
  • @czerspalace Shame on me but I just replaced get_results with get_var, and honestly I have no idea what should I do with that. Could you give me a hand? I literally spent on it the whole day trying to make it work :P
    – Rafal
    Oct 18, 2016 at 19:54
  • When you replaced it, what did you see in $sub_orders? Oct 18, 2016 at 19:59

1 Answer 1

0

Okay, I figured it out:

global $wpdb;
 $par_order = $reservation->transaction_id;
$store = wp_get_current_user();
$store_id = $store->ID;
    $sql = "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order' AND post_parent = $par_order AND post_author = $store_id";
$sub_orders = $wpdb->get_var($wpdb->prepare($sql,$seller_id));

thank you @czerspalace for the clue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.