I’m doing the following in a custom function:
$exists = $wpdb->query($wpdb->prepare('
SELECT COUNT(*)
FROM wp_%d_gdsr_data_article
WHERE post_id = %d
', $blog_id, $post_id));
$exists evaluates to 1 even if no rows are returned by the query. Also, var_dump($wpdb->queries) yields a NULL. Anyone know what is going on here?
thanks,
From the documentation:
The query returns 1 row so the
query()function returns1– and will always return1for the query that you post in your question, even if the number of rows selected by theCOUNTis 0. Useget_var,get_row, orget_resultsas suggested by TheDeadMedic to get the actual result of the query, which might be0,1,2, etc.