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:

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

2 Answers
2

$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.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *