wpdb-> not adding prefix to custom table

I know it should work with custom table and I think it worked in previous development I believe. But this time I don’t know whey it is not getting custom table with $wpdb->tablename

Code:

Read More
global $wpdb;    
$items = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->review_media"));

This is not giving any result but when I tried with `$wpdb->prefix than it works

$wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM ".$wpdb->prefix."review_media"));

Any idea

Related posts

Leave a Reply

2 comments

  1. $wpdb->tablename works only with the tables initially present in a WordPress installation. These tables are defined in wp-includes/wp-db.php.

    The second method you used is perfectly acceptable.

  2. You are supposed to store the table name in $wpdb before you can use it the way you did.

    $wpdb->review_media = "{$wpdb->prefix}review_media";