0

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!

1 Answer 1

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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