Here is my query, when i run this in PHP file its returns NULL but same query in Phpmyadmin return row.

Even I tried with $wpdb->get_row() and $wpdb->get_col() but the result is same for all.

include 'wp-config.php';
global $wpdb;
$result = $wpdb->get_results("SELECT * FROM wp_order_transaction WHERE order_id=1431");

can any one tell me where is my mistake. Thanks in advance!

  • @N00b : no $wpdb can read data from custom table also, please review : codex.wordpress.org/Class_Reference/wpdb – Jaydeep Pandya May 11 '16 at 7:03
  • 1
    Why you are including include 'wp-config.php'; config file ? – Sumit May 11 '16 at 7:04
  • 1
    Then it is not the right way to include the WordPress. Search the site you will see how you can load WordPress in a separate file. – Sumit May 11 '16 at 7:07
  • 2
    I just tested the same code, and it is working. You must test it with clean install. – Sumit May 11 '16 at 13:25
  • 2
    yes strange @Sumit in my localhost its not working but same code working on live well..! anyways Thanks your advice is better to include file in proper way. – user2134 May 12 '16 at 5:41

You need to include the "wp-load.php" file at the top of the code

| improve this answer | |

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