开发者

wordpress query

开发者 https://www.devze.com 2022-12-24 00:34 出处:网络
How do 开发者_如何学CI query posts from a category using more than 1 custom key/value pair?$query =\"SELECT * FROM dishes \" ;

How do 开发者_如何学CI query posts from a category using more than 1 custom key/value pair?


$query =  "SELECT * FROM dishes " ;

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


You can include postmeta several times.

$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);


There's lots of information about this here

For example...

$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

精彩评论

暂无评论...
验证码 换一张
取 消