I am currently working on a WordPress project that has the WooCommerce plugin on it for the store. However all the billing info from orders go to the wp_postmeta table, where the all of the info is saved in the same column, "meta_value".
I have a form, that a customer can fill out using their order number, first name and post number, and after filing this field their order would show on the site.
Hence in my query I would only like to check if the user inputted order number, first name and post number are true, and I don't need anything else from the column.
I have made a test order with my credentials and at the moment my query looks like this, but it finds two results because there are two fields in the wp_postmeta table that have the same order number and the same first name in them as the order:
$ordernumber = $_POST['ordernmbr'];
$orderfirstname = $_POST['firstname'];
$orderpostnumber = $_POST['postnmbr'];
$sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}postmeta
WHERE post_id = %d AND meta_value = %s",
$ordernumber, $orderfirstname);
$res = $wpdb->get_results($sql, ARRAY_A);
Ask me if anything was unclear, I'm pretty bad at explaining things!
EDIT: Updated query after getting help from Vel, still not working as intended as the query doesn't want to find any results.
$sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}postmeta
WHERE post_id = %d AND (meta_value = %s AND meta_key ='_billing_first_name' AND meta_value = %s AND meta_key ='_billing_postcode') ",
$ordernumber, $orderfirstname, $orderpostnumber );
$res = $wpdb->get_results($sql, ARRAY_A);