dpw63348 2014-10-15 01:20
浏览 44

wpdb->查询来自table1检查元数据并发布状态

I have a fairly complex need, which I am not entirely certain of where to start due to my somewhat limited knowledge of WordPress's database structure and everything.. So here's what I have going on.

I have a custom table that would look something like this:

wp_buzzsumo

+--------------------------------------+
| id  pageID  title  totalShares  date |
+--------------------------------------+
| 1   25      -      20000        -    |
| 2   29      -      1992         -    |
| 3   25      -      122345       -    |
| 4   27      -      134          -    |
+--------------------------------------+

I have a WordPress query that looks like this:

SELECT * FROM wp_buzzsumo ORDER BY totalShares DESC LIMIT 20

And then in the loop in PHP where I output the results, I have some statements to check some things.. But now due to the LIMIT of 20 in some cases it does not return anything because the top 20 results fail the if statements... So now I need a way to put these statements into the query..

if(
    !get_field("hide_trending_bar", $PageID) && 
    !get_field("hide_hashtags_from_trending_bar", $PageID) && 
    get_page($PageID)->post_status == "publish"
  )

$PageID would have to match the pageID column in the table above.

I need a query something like this I believe.. But I know this isn't quite the right way of doing this..

 SELECT * FROM wp_buzzsumo 
 WHERE wp_posts.pageID=wp_buzzsumo.pageID 
 AND wp_posts.post_status = 'publish'
 AND (
      wp_posts.meta_key = 'hide_trending_bar'
      AND 
      wp_posts.meta_value = ""
      )
 AND (
      wp_posts.meta_key = 'hide_hashtags_from_trending_bar'
      AND 
      wp_posts.meta_value = ""
      )

 ORDER BY totalShares DESC LIMIT 20
  • 写回答

1条回答 默认 最新

  • drip5880 2014-10-15 04:26
    关注

    another approach :-

    $pageids = $wpdb->get_col("SELECT id FROM {$wpdb->prefix}buzzsumo ORDER BY totalShares DESC LIMIT 20",ARRAY_N);
    
    $args = array(
        'post_status'      => 'publish',
        'post_status'      => 'page',
        'include'          => $pageids,
        'meta_query'       => array(
            'relationship' => 'AND',
             array(
                'key'      => 'hide_trending_bar',
                'value'    => '',
                'compare'  => '='
            ),
            array(
                'key'      => 'hide_hashtags_from_trending_bar',
                'value'    => '',
                'compare'  => '='
            ),
    
        )
    );
    $posts = get_posts( $args );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c