i create simple plugin , it work in main page , but when i create a link to user go to the another page for see informaation , it show me Fatal error: Uncaught Error: Call to a member function get_results()
my code is :
<?php
global $wpdb;
$results = $wpdb->get_results("SELECT * FROM wp_customers");
?>
<body>
<table>
<tr>
<th>âID</th>
<th>Name</th>
<th>Family</th>
<th>Numbers</th>
<th>Tell</th>
</tr>
<?php foreach($results as $results){
?>
<tr>
<td>
<?php echo $results->id; ?>
</td>
<td>
<?php echo $results->name; ?>
</td>
<td>
<?php echo $results->family; ?>
</td>
<td>
<?php echo $results->numbers; ?>
</td>
<td>
<?php echo $results->tell; ?>
</td>
<?php }?>
</tr>
</table>
You need to check you have not set up the database prefix to something other than ‘wp_’.
And if you have wp_ prefix in the database then you have to included wp-load file on the custom page.
If it’s a plugin then you should encapsulate your code in a function and hook this funtion to the wordpress “init” action, so in your plugin file you should have somthing like this :