Support

Account

Home Forums Add-ons Repeater Field Sort by date in repeater field

Solved

Sort by date in repeater field

  • Hi,

    My repeater is “dates” with sub value “date_spectacle”
    this query returns posts of a given month, but only on the first sub value of the repeater (dates_0_date_spectacle)
    How could i do look for for in all rows ? dates_%date_spectacle ???

    (ACF date return value set on ‘d-m-y’)

    Thanks

    $today = date("d/m/Y");
    
    $themonth=substr($today, 3,2);
     
    $args = array (
        'post_type'       => 'spectacle',
        'numberposts' => -1,
        'post_status'=>'publish',
        'meta_key'        => 'dates_0_date_spectacle',
        'meta_value'      => '[0-9]{4}' . $themonth . '[0-9]{2}',
        'meta_compare'    => 'REGEXP',
    );
  • Elliot please would you have an idea ?
    thanks

    i also try to get all spectacle where date >= date today but i don’t know how

    • Elliot

    • February 17, 2015 at 9:33 am

    Hi @pipoulito

    Posts can only be ordered by 1 custom field, so it is not possible to order by multiple sub fields fortunately.

    • Elliot

    • February 17, 2015 at 9:35 am

    Hi @pipoulito

    On second thought, it may be possible, however, the performance would be quite slow.
    Please read over this doc to get some starter code:
    http://www.advancedcustomfields.com/resources/querying-the-database-for-repeater-sub-field-values/

    Thanks
    E

  • thanks Elliot, but i sometimes seen this expression with % : dates_%_date_spectacle

    does no it means all fields ?
    thanks

    • Elliot

    • February 26, 2015 at 2:56 pm

    Hi @pipoulito

    Sorry, but I don’t understand your last question.

    The % is a wildcard and will match any string which allows it to work with the repeater field incremental numbers for sub field keys

  • ok thanks so would you mean this code should show
    only EVENT where month=current month ?
    thnaks

    $today = date("d/m/Y");
    
    $themonth=substr($today, 3,2);
     
    $args = array (
        'post_type'       => 'EVENT',
         'meta_key'        => 'dates_%_date_EVENT',
        'meta_value'      => '[0-9]{4}' . $themonth . '[0-9]{2}',
        'meta_compare'    => 'REGEXP',
    );
    • Elliot

    • March 5, 2015 at 6:10 pm

    Hi @pipoulito

    You will also need to hook into the posts_where filter and add some extra code to allow for the meta_key to match via LIKE.

    Checkout the following doc for more info
    http://www.advancedcustomfields.com/resources/how-to-query-posts-filtered-by-custom-field-values/#example-5

Viewing 8 posts - 1 through 8 (of 8 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.