dongyoucha0645 2019-07-08 17:05
浏览 90

在与当前日期进行比较时,通过多个元键查询帖子不起作用

I am writing a code to query posts meta value based on other meta value compare date, below is my code, it query all posts ignoring the date condition:

i have tried to use 'LEFT JOIN" sentence with no success

$querystr = "
SELECT DISTINCT m2.meta_value as 'appdata'
FROM $wpdb->posts
INNER JOIN $wpdb->postmeta m1 ON ($wpdb->posts.ID = m1.post_id AND m1.meta_key LIKE 'repeater_%_date' AND m1.meta_value > NOW())
INNER JOIN $wpdb->postmeta m2 ON ($wpdb->posts.ID = m2.post_id AND m2.meta_key LIKE 'repeater_%_appdata' AND m2.meta_value != '')
WHERE $wpdb->posts.ID = m1.post_id
";

$pageposts = $wpdb->get_results($querystr, ARRAY_A);

The problem is this code query the old and new posts which has the date meta key

Note: repeater_%_date is ACF date field storing the date as Ymd (20190708)

Any solution please?

  • 写回答

1条回答 默认 最新

  • douna4762 2019-07-11 06:12
    关注
    $get_featured_args3  = array(
                  'post_type'  => 'post',
                  'orderby'     => 'date',
                  'order'       => 'DESC',
                  'posts_per_page'=>-1,       
                  'meta_query' => array(
                        'relation' ->'AND',
                        array(
                            'key'     => 'key1',
                            'value'   => 1,
                            'compare' => '=',
                        ),
                        array(
                            'key'     => 'key2',
                            'value'   => 1,
                            'compare' => '=',
                        ),
                    ),
                    'date_query' => array(
                        array(
                            'year' => date('Y'),
    
                        ),
                    ),
                );
        $get_featured_results3 = new WP_Query( $get_featured_args3 );
    
        $posts = $get_featured_results3->posts;
        foreach($posts as $post){
    
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)