【问题标题】:wordpress querywordpress 查询
【发布时间】:2010-03-19 12:06:29
【问题描述】:

如何使用超过 1 个自定义键/值对查询某个类别的帖子?

【问题讨论】:

    标签: php mysql wordpress


    【解决方案1】:
    $query =  "SELECT * FROM dishes " ;
    
    $return  = $db->query( $query ) ; 
    

    【讨论】:

      【解决方案2】:

      您可以多次包含 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);
      

      【讨论】:

      • 啊哈!那么这个查询如何与类别 ID 选择一起工作?
      【解决方案3】:

      有很多关于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);
      

      【讨论】:

        猜你喜欢
        • 2015-12-09
        • 2012-10-28
        • 2011-06-16
        • 2020-04-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-14
        相关资源
        最近更新 更多