I have a function in a WordPress plugin I am about to write (my first one) that should check if a given ID belongs to a user with a certain role ('dance_couple' in this case).
$sc_user_id is the id passed in the shortened code.
function user_is_dance_couple($sc_user_id){
global $wpdb;
$count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->usermeta WHERE user_id = %d AND meta_value LIKE `%dance_couple%`", $sc_user_id));
if($count == 1){ return true; } else { return false; }
}
if (user_is_dance_couple(1)) {
// here comes what should be done if the user has the right role
}
Question: The weird thing is, that I copied a simpler version of the function (https://wordpress.stackexchange.com/questions/165691/how-to-check-if-a-user-exists-by-a-given-id) and adapted it. so the only thing I changed is the bit of sql code (that works fine in sql), the function as it was before also works fine - I have no idea what I did wrong.
I already tried:
- changing the single quotes to the thing between the double quotes " ` "
- taking the sting out and adding it in a variable
- adding the table names in before the columns
Thanks for the help!
$stringis not doing anything, so it should be removed$stringvariable from your query and after check it?%dance_couple%should be '%dance_couple%'