2010-03-19 67 views

回答

0

可以包括postmeta幾次。

$querystr = " 
    SELECT wposts.* 
    FROM $wpdb->posts wposts, 
     $wpdb->postmeta wpostmeta1, 
     $wpdb->postmeta wpostmeta2 
    WHERE wposts.ID = wpostmeta1.post_id 
    AND wposts.ID = wpostmeta2.post_id 
    AND wpostmeta1.meta_key = 'tag' 
    AND wpostmeta1.meta_value = 'email' 
    AND wpostmeta2.meta_key = 'anothertag' 
    AND wpostmeta2.meta_value = 'anothervalue' 
    AND wposts.post_status = 'publish' 
    AND wposts.post_type = 'post' 
    ORDER BY wposts.post_date DESC 
"; 

$pageposts = $wpdb->get_results($querystr, OBJECT); 
+0

aha!那麼這個查詢如何處理類別ID選擇? – InnateDev 2010-03-21 14:38:17

0

有很多信息this here

例如...

$querystr = " 
    SELECT wposts.* 
    FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta 
    WHERE wposts.ID = wpostmeta.post_id 
    AND wpostmeta.meta_key = 'tag' 
    AND wpostmeta.meta_value = 'email' 
    AND wposts.post_status = 'publish' 
    AND wposts.post_type = 'post' 
    ORDER BY wposts.post_date DESC 
"; 

$pageposts = $wpdb->get_results($querystr, OBJECT); 
+0

試過 - - 它只有一個鍵/值對 – InnateDev 2010-03-19 12:45:21

1
$query = "SELECT * FROM dishes " ; 

$return = $db->query($query) ;