Home Forums General Issues Sort event by month with meta_compare


Sort event by month with meta_compare

  • Hi,
    Please, this should work , i don’t why it does not….
    try to only get spectacle of the current month.
    dates_0_date_spectacle is a repeater field should return something like dd/mm/yyyy
    so i extract ‘mm’ with substr and compare it to $month

    $today = date("d/m/Y");
    $month = substr($today, 3,2) /// '02' (february)
    $args = array (
        'post_type'       => 'spectacle',
        'meta_key'        => substr(get_field('dates_0_date_spectacle'), 3,2) ,
        'meta_value'      => $month , 
        'meta_compare'    => '=',
  • Hi @pipoulito

    Thanks for the post.

    Due to the save format of the date picker field, to successfully order your posts the format has to be yymmdd($php = “Ymd”).

    You can add this to your query logic to sort the posts.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Sort event by month with meta_compare’ is closed to new replies.