I am aware of this SO post. However, my prepared statement is still not working.
Here's the array called $parameterized
:
array(4) {
[0]=>
string(11) "1234567"
[1]=>
string(11) "1234567"
[2]=>
string(17) "%36.5 (u.s. 6.5)%"
[3]=>
string(13) "%37 (u.s. 7)%"
}
Here's my prepared query called $query
:
SELECT DISTINCT products.*, prices.max_price, prices.min_price, prices.compare_at_price, collects.position
FROM products
INNER JOIN collects
ON products.product_id = collects.product_id
AND collects.collection_id = %d
INNER JOIN (
SELECT variants.product_id, MAX(variants.price) AS max_price, MIN(variants.price) AS min_price, MAX(variants.compare_at_price) AS compare_at_price
FROM variants
INNER JOIN collects
ON variants.product_id = collects.product_id
WHERE collects.collection_id = %d AND (variants.option1 LIKE ? OR variants.option1 LIKE ?)
GROUP BY product_id ORDER BY NULL
) prices ON products.product_id = prices.product_id
ORDER BY collects.position ASC LIMIT 0,12
And here's the prepared statement of that prepared query when I execute $productsQuery = $wpdb->prepare($query, $parameterized)
:
SELECT DISTINCT products.*, prices.max_price, prices.min_price, prices.compare_at_price, collects.position
FROM products
INNER JOIN collects
ON products.product_id = collects.product_id
AND collects.collection_id = 1234567
INNER JOIN (
SELECT variants.product_id, MAX(variants.price) AS max_price, MIN(variants.price) AS min_price, MAX(variants.compare_at_price) AS compare_at_price
FROM variants
INNER JOIN collects
ON variants.product_id = collects.product_id
WHERE collects.collection_id = 1234567 AND (variants.option1 LIKE ? OR variants.option1 LIKE ?)
GROUP BY product_id ORDER BY NULL
) prices ON products.product_id = prices.product_id
ORDER BY collects.position ASC LIMIT 0,12
Notice here, WHERE collects.collection_id = 97476673649 AND (variants.option1 LIKE ? OR variants.option1 LIKE ?)
where ?
the question marks are and how they are not getting replaced with "%36.5 (u.s. 6.5)%"
or "%37 (u.s. 7)%"
.
Is there something wrong with my $parameterized
array? Are my LIKE arguments in that array incorrect? Or is the symbol ?
in my SQL string -- variants.option1 LIKE ? OR variants.option1 LIKE ?
-- invalid?