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
$wpdb->tablename
works only with the tables initially present in a WordPress installation. These tables are defined inwp-includes/wp-db.php
.The second method you used is perfectly acceptable.
You are supposed to store the table name in $wpdb before you can use it the way you did.