Support

Account

Home Forums Add-ons Repeater Field Order Repeater Field Rows by Date Picker

Solving

Order Repeater Field Rows by Date Picker

  • So I’ve read quite a few posts here in the forum but haven’t been able to get the solutions to work for me yet.

    I want to display all of my Books in order of publish date (most recent at the top). This value comes from a repeater date picker field (publish_date). My dates are formatted as (F Y).

    Here is my code so far:

    <?php if (have_rows('scholarly_books') ):
    while (have_rows('scholarly_books') ): the_row(); ?>
                    
    <!-- START THE REPEAT SECTION -->
    <h2><?php the_sub_field('book_title'); ?></h2>
    <p>Published in: <?php the_sub_field('publish_date'); ?></p>
    <!-- END OF THE REPEAT SECTION -->
    
    <?php endwhile; ?>
    <?php endif; ?>

    Im not sure what I am missing following the other examples, but I would appreciate any help that you could offer.

    Thanks!

  • The first thing that you’re going to need to do is alter the format date, of get the date without formatting so that it’s in a format that can be sorted. This will depend on if you’re using ACF 4 or 5. In 4 you set the storage format, in 5 the storage format is always ‘YYYYMMDD’ which makes it sortable. You can get an un-formatted field value by including a 3rd argument when calling get_sub_field()

    Getting a value without formatting is covered on this page http://www.advancedcustomfields.com/resources/get_field/

    and sorting the rows of a repeater is covered here http://www.advancedcustomfields.com/resources/how-to-sorting-a-repeater-field/

  • I am using Version 5.3.2.2. Could you please show me? I haven’t been able to convert the other samples I have read in the forum to work for me.

    Thanks!

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

The topic ‘Order Repeater Field Rows by Date Picker’ is closed to new replies.