In WooCommerce habe ich die folgende SQL-Abfrage, um Elternprodukte auszuwählen. Ich möchte nur das "Lager" Produkt auswählen.Erhalten Sie alle übergeordneten Produkte mit "instock" Lagerstatus in WooCommerce
Dies ist meine eigentliche SQL-Abfrage:
$query=$db->query("select * from wp_posts
where post_parent='0' and post_type='product' and post_status='publish'
group by ID
limit 10");
Wie kann ich auswählen nur "auf Lager" parent Produkte (aber nicht alle)? :
global $wpdb;
// The SQL query
$results = $wpdb->get_results("
SELECT p.*, pm.meta_value as stock_status
FROM {$wpdb->prefix}posts as p
INNER JOIN {$wpdb->prefix}postmeta as pm ON p.ID = pm.post_id
WHERE p.post_type LIKE 'product'
AND p.post_status LIKE 'publish'
AND p.post_parent = '0'
AND pm.meta_key LIKE '_stock_status'
AND pm.meta_value LIKE 'instock'
GROUP BY p.ID
");
// Testing output (objects array)
echo '<pre>'; print_r($results); echo '</pre>';
geprüft und Arbeiten
Update Ihre Frage eine richtige Datenprobe und das erwartete Ergebnis – scaisEdge
@scaisEdge wie gewünscht – kashalo
aktualisiert hinzufügen sehe ich keine nennenswerte .. Probe Daten .. – scaisEdge