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 626 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Accessing ACF Repeater Sub Fields Programmatically in Bricks Query Loop

Accessing ACF Repeater Sub Fields Programmatically in Bricks Query Loop

It is possible to output sub field's values when a Bricks query loop's type has been set to a ACF Repeater without writing code. This…
Categories:
Pro
Inserting Random Ad Between Posts in Bricks

Inserting Random Ad Between Posts in Bricks

How to insert random ads (post type) in between regular posts on the blog page.
Categories:
Pro
Related FAQs on Product pages Based on Product Category Taxonomy in Bricks

Related FAQs on Product pages Based on Product Category Taxonomy in Bricks

On product pages, we show all the FAQs associated with the current WooCommerce product's product categories.
Categories: