Visual composition of a custom query string column for past events

I want to display past events on the home page. I am using the post-grid visual layout custom query parameter to compare with the current date and the messages displayed are less than the current date.

post_type=event&posts_per_page=3&post_status=publish&orderby=meta_value_num&order=DESC&meta_key=date_short_order&meta_value=$today&compare=<&type=DATE

      

I used this query but didn't work

+3


source to share


1 answer


select the past event from the current date

post type "event" and meta-key name "date_short_order"

<?php
$today = date("Y/m/d h:i A");
$event_args=array(
    'type'                     => 'event',
    'post_status'              => 'publish',
    'posts_per_page'           => 3,
    'meta_key'                 => 'date_short_order', //event_date
    'orderby'                  => 'meta_value_num', //or 'meta_value_num' , 'meta_value'
    'meta_query' => array(
                        array('key' => 'date_short_order',
                              'value' => $today, 
                              'compare' => '=<',
                              'type' => 'DATE',
                        )
                    ),
    'order'                    => 'DESC',
);
$event_my_query = null;
$event_my_query = new WP_Query($event_args);

if( $event_my_query->have_posts() ) 
{
     while ($event_my_query->have_posts()) : $event_my_query->the_post(); 
        the_title();
      endwhile;
}
wp_reset_query($event_my_query);
?>

      

[] is replaced with% 5B% 5D at URL encoding time.

'[' =% 5B



']' =% 5D

post_type=event&posts_per_page=3&post_status=publish&meta_key=date_short_order&orderby=meta_value_num&order=DESC&meta_query[0][key]=date_short_order&meta_query[0][value]=$today&meta_query[0][compare]=<&meta_query[0][type]=DATE

      

visual composition of custom query string column for past events:

post_type=event&posts_per_page=3&post_status=publish&meta_key=date_short_order&orderby=meta_value_num&order=DESC&meta_query%5B0%5D%5Bkey%5D=date_short_order&meta_query%5B0%5D%5Bvalue%5D=$today&meta_query%5B0%5D%5Bcompare%5D=<&meta_query%5B0%5D%5Btype%5D=DATE

      

+1


source







All Articles