Custom meta wordpress (no result)

Problem

I iterate over custom post types (advanced custom fields) in Wordpress. I need to display events with start_date equal to the $ newdate variable defined at the beginning.

The start_date is in the format YYYY-MM-DD HH: mm (same as $ newdate). $ newdate is set at the beginning of the day, so I do not exclude events with different hours per day, and for comparison, I set a value greater (just to check the request).

However, I am not getting any results.

<?php
$newdate = date('Y-m-d 00:00');
//<-- Start the Loop. -->!
$args = array( 
        'post_type' => 'epsa_events', 
        'posts_per_page' => 5,
        'orderby' => 'meta_value',
        'order' => 'ASC',
        'meta_query' => array (
            array(
            'key' => 'start_time',
            'value'   => $newdate,
            'compare' => '>=',
            'type' => 'datetime' 
            )
        )
    );

$loop = new WP_Query( $args );
+4
source share
2 answers

Try this query: -

'meta_key'   =>  'event-start-date',
'meta_query' => array (
            array(
            'key' => 'start_time',
            'value' => date('Ymd',strtotime($newdate)),
            'compare' => '>=',
            'type' => 'date' 
            )
        )
0

, .

-, 'orderby' => 'meta_value', 'meta_key' => KEYVALUE $args, KEYVALUE - , . WP_Query .

-, , , start_date - , , , . , , , $args :

$args = array(
    'post_type'      => 'epsa_events',
    'posts_per_page' => -1,
    'orderby'        => 'meta_value',
    'order'          => 'ASC',
    'meta_key'       => 'start_time',
    'meta_type'      => 'DATETIME'
    'meta_query'     => array (
        array(
            'key'     => 'start_time',
            'compare' => '<=',
            'value'   => $newdate,
            'type'    => 'DATETIME'
        )
    )
);

.

, !

0

Source: https://habr.com/ru/post/1622631/


All Articles