1

I am trying to get meta_value from postmeta using SQL select query, but it returns wc_order_h8K0C1ODu2134 instead of meta_value which is Table No 10

   global $wpdb;

   $order_id = $order->get_id();
   $order_num = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = 
   $order_id" ) );

   echo $order_num->post_id;  //which is 274 ok
   echo $order_num->meta_value;  // but meta_value retrun wc_order_h8K0C1ODu2134 and it should be Table No 10

I need to manipulate meta_value at thankyou page, eg. if the admin change Table No 10 to Table No 12 while the user is waiting for the admin response

but without having meta_value, I can't do that.

so how can I get meta_value which is Table No 10 (and not that wc_order_h8K0C1ODu2134)

I have tried different SQL techniques but it always returns wc_order_h8K0C1ODu2134.

Thanks

user1781038
  • 111
  • 3
  • 10
  • Have you tried [get_post_meta](https://developer.wordpress.org/reference/functions/get_post_meta/) function ? Or check this [answer](https://stackoverflow.com/questions/25635461/get-post-meta-in-woocommerce-email-notifications#answer-27573523) @user1781038 – Sergey Ligus Nov 17 '21 at 20:42
  • @sergey Ligus Aleady using get_post_meta. it's working fine. but my problem is continuously fetching updated value from the database, because if the admin update the table number then I have to show updated value instantly on thankyou page – user1781038 Nov 18 '21 at 00:48
  • Please add screenshots of your post meta table with value. – Bhautik Nov 18 '21 at 06:01
  • 1
    `Table No 10` is a value of meta field in `post_meta` table or its a custom created table or both?) If i understand you correctly then you need to get a fresh meta value from `post_meta` and then make a custom query to your custom table, like this `Select * from {$meta_value}` dynamically. You can use the same methods from `$wpdb` as you did before to query your custom tables. Did typo in example query, redo the comment ) @user1781038 – Sergey Ligus Nov 18 '21 at 08:23
  • 1
    ` global $wpdb; $order_id = $order->get_id(); $order_num = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = $order->id AND meta_key ='_table_no'" ) ); echo $order_num->post_id; echo '
    '; echo $order_num2 = meta_value;` here is finished code now its working fine. now i need to fetch data like every 5 second. with the help of this https://codex.wordpress.org/AJAX_in_Plugins not succeed yet.
    – user1781038 Nov 19 '21 at 00:12

0 Answers0