26th Sep '24
/
0 comments

Sorting ACF Repeater Rows in Bricks by Date Sub Field

Sorting ACF Repeater Rows in Bricks by Date Sub Field

This Pro tutorial shows how the rows of a ACF Repeater query loop in Bricks can be sorted by ascending or descending order of a date sub field.

Consider this example:

Testimonials (Repeater)|_ Testimonial Content (WYSIWYG Editor)|_ Client Name (Text)|_ Testimonial Date (Date Picker)

Sample testimonials for a post:

Output on the front end by default:

Note: To change the order, the rows can simply be re-arranged by drag and drop in the post editor. This tutorial is when the ordering should happen automatically.

After implementing the tutorial:

Ascending order of date:

Descending order of date:

Step 1

Set Return Format for the date sub field to Ymd.

To output the date in a human-friendly format, add the desired format string like :F Y at the end for the value of your Basic Text element.

Ex.:

{acf_testimonials_testimonial_date:F Y}

Step 2

Add the following in child theme's functions.php (w/o the opening PHP tag) or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Limit Bricks Users Query to Current Post’s User-type ACF Field Value

Limit Bricks Users Query to Current Post’s User-type ACF Field Value

Consider this scenario with ACF: "John Briley" user: "Gandhi" movie: The requirement is to show John Briley as the author when Gandhi movie item is…
Categories:
Pro
Filtering posts by a group field’s true / false field sub field value with ACF or Meta Box in Bricks

Filtering posts by a group field’s true / false field sub field value with ACF or Meta Box in Bricks

This Pro tutorial covers how posts of a Bricks query loop can be filtered to show only the ones whose true / false or checkbox…
Categories:
Tags:
Color Custom Field as Section Background Color on Category/Term Archives in Bricks

Color Custom Field as Section Background Color on Category/Term Archives in Bricks

How to use a color from a taxonomy term custom field for as the hero section background color on archive pages.
Categories:
Tags:
How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 1)

How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 1)

This tutorial provides the PHP & JS codes that can be pasted in order to create a dynamic map with markers populated from a custom…
Categories:
Show Product Categories Count Using Bricks Filter Hook

Show Product Categories Count Using Bricks Filter Hook

Unable to find terms count from the Dynamic Data provided by Bricks theme? It's okay, this simple tutorial shows you how to properly get the…
Categories:
Tags:
Pro
Bricks Dynamic Data Tag for Text-type Custom Field Value with Word Limit

Bricks Dynamic Data Tag for Text-type Custom Field Value with Word Limit

How to register a new dynamic tag for setting excerpt word limits and outputting an ellipsis (...) at the end.
Categories: