Support

Account

Home Forums General Issues Sort event by month with meta_compare

Solved

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'    => '=',
    );
    • James

    • April 5, 2016 at 11:53 pm

    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)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.