Filter dates using WP_query and Post meta in Wordpress

1

I'm developing a category of events in my template using the standard post, in this post I've added two fields (Metabox) to the start date and end date of the event. Already in WP_query I need to display the events that have the starting date smaller than the current date, and the shorter end date.

Using WP_query or get_post_meta, or any other function ... How can I do this?

    
asked by anonymous 23.07.2014 / 05:02

1 answer

2

In case this depends on the way you save the date ... I recommend using the format:

YmdHis

In this way you can make a very simple query by buying numbers only:

'meta_query' => array(
    array(
        'key' => 'seu_meta_key',
        'value' => array( 'data_atual', 'data_termino' ),
        'compare' => 'BETWEEN',
        'type' => 'NUMERIC'
    )
);

You can also try to use type as DATE , but to do that you will also have to use a date format as I said.

For more details refer to meta_query documentation on WP_Query .

    
24.07.2014 / 20:20