admin管理员组

文章数量:1122846

I'm working on a query where I have a few conditions, one of them involving post_date. However, whenever I try to write my query, post_date doesn't return any matches. If I comment that part out, it will return matches (but not quite to where I need). If I only have the post_date query uncommented, it returns 0 results.

Is anyone able to help point me in the right direction?

$date_seven = date('Y-m-d H:i:s', strtotime('-7 days'));

'meta_query' => array(
                'relation' => 'AND', 
                // show posts where location is US
                array(
                    'key' => 'monitor_settings_location',
                    'value' => 'US',
                    'compare' => 'LIKE'
                ),
                    array(
                    'relation' => 'OR',
                    // if end date is empty, show for 7 days after publish date
                    array(
                        'relation' => 'AND',
                        array(
                            'key' => 'monitor_settings_end_date',
                            'value' => '',
                        ),
                        array(
                            'key' => 'post_date',
                            'value' => $date_seven,
                            'compare' => '>=',
                            'value' => 'DATETIME'
                        )
                        ),
                        // if end date exists, show until that date
                        array(
                            'key' => 'monitor_settings_end_date',
                            'value' => $date_now,
                            'compare' => '>='
                            'value' => 'DATETIME'
                        )
                )
            )

Using var_dump on the results with the post_date aspect commented out gives me public 'post_date' => string '2024-06-28 12:29:52' (length=19)

本文标签: wp querymetaquery postdate not returning results