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 Commented Oct 18, 2016 at 19:03
  • @czerspalace Unfortunetely it hasn't helped. Commented Oct 18, 2016 at 19:24
  • Is it still returning an array? Can you show your updated code with get_var? Commented 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 Commented Oct 18, 2016 at 19:54
  • When you replaced it, what did you see in $sub_orders? Commented 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.