## wpdb – SQL/WordPress, checking if column contains specific text (and then getting count) not working

Question

I have a table called wp_rsvp. Within this table I have a column called cot_needed which has the values of “yes” or “no”.

In my table, I have two rows, one where cot_needed is “yes” and one where cot_needed is “no”.

I’m trying to get a count of the rows where cot_needed is equal to “yes”.

To do this, I have the following, which I have found recommended on other SO questions:

$rsvp_table =$wpdb->prefix . 'rsvp';
$cots_needed_count =$wpdb->get_var( "SELECT COUNT(*) FROM $rsvp_table WHERE 'cot_needed' LIKE '%yes%'");  However, when I run echo$cots_needed_count; it returns 0, even through a row with “yes” exists? The echo should print 1.

0
1 month 2023-01-01T09:58:15-05:00 0 Answers 0 views 0