0

我正在编写一个代码来根据其他元值比较日期查询帖子元值,下面是我的代码,它查询所有帖子忽略日期条件:

我尝试使用“LEFT JOIN”句子但没有成功

$查询字符串 = "
选择 DISTINCT m2.meta_value 作为 'appdata'
来自 $wpdb->帖子
内部连接 ​​$wpdb->postmeta m1 ON ($wpdb->posts.ID = m1.post_id AND m1.meta_key LIKE 'repeater_%_date' AND m1.meta_value > NOW())
内部连接 ​​$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);

问题是此代码查询具有日期元键的旧帖子和新帖子

注意: repeater_%_date 是 ACF 日期字段,将日期存储为 Ymd (20190708)

请问有什么解决办法吗?

4

1 回答 1

0
$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){

    }
于 2019-07-11T06:12:59.897 回答