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

I want to count the number of rows of this custom wordpress query and it does not work:

*PS I am accessing a custom table inside my wordpress database, mabe by myself. The $wpdb->get_results part works.*

$myquery = $wpdb->get_results("SELECT COUNT(*) FROM `$table` WHERE $myconditions"); 
$nr = $myquery->num_rows;

Any ideas why?

Important: using $wpdb->get_results like this:

  • Do I need to prepare the query (i read it in the codex)?
  • Do I need to somehow reset the query after I have used it?

Ty for helping!

share|improve this question
up vote 0 down vote accepted

Doing a Select Count(*) ... will only ever output one row with a single value - the number of rows that satisfied your where clause.

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.