Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.