WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my plugin code, I am pulling the table id from two tables. The id is being pulled from one table but not from the other and I get errors in both instances. The queries work on mysql when I use them. any thoughts? code is below and output below that. The id gets pulled from the wp_shclass table but not the wp_shinstructor table. Any thoughts I have been staring at this for a few days and am not sure what's wrong. I am using wp 3.3.1

function shmain_admin(){
if (!current_user_can('manage_options'))  {
wp_die( __('You do not have sufficient permissions to access this page.') );

echo "Hello class";
global $wpdb;
$shrow = $wpdb->get_row("select * from wp_shclass ORDER BY classid DESC LIMIT 1", ARRAY_A);  
$shclassid = $shrow['classid'];
echo "<br> this is " . $shclassid;
echo "<br> Hello instructor";
$shrow = $wpdb->get_row("select * from wp_shinstructor ORDER BY instructorid DESC LIMIT 1", ARRAY_A);  
$shinstructorid = $shrow['instructorid'];
echo "<br> this is " . $shinstructorid;

function shmain_admin_action(){
add_menu_page('sh main', 'main', 'manage_options','shmain', 'shmain_admin');


and here is the output below

Hello class this is 8

WordPress database error: []
select * from wp_shclass ORDER BY classid DESC LIMIT 1

Hello instructor this is

WordPress database error: []
select * from wp_shinstructor ORDER BY instructorid DESC LIMIT 1
share|improve this question

In general, I'd recommend to read about $wpdb in detail in the Codex.

Some notes:

  1. Never use the default wp_ prefix.
  2. Never set a hard coded prefix. It will be set during installation and should later be added using $wpdb->prefix. But: Prefixes can be changed with the following SQL command. "RENAME table wp_posts TO {$wpdb->prefix}posts;"
  3. Normally there's always a way to get around custom tables. CPTs and Custom Taxonomies are just an example.
share|improve this answer
Thanks Kaiser I will check out CPTs and custom taxonomies – wpuserpj Mar 30 '12 at 11:30
up vote 0 down vote accepted

Deleting the tables and recreating them solved the problem. The problem was in how I had created the tables

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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