Home › Forums › Add-ons › Repeater Field › Filter Sort Repeater Field in Backend
Hi, i’ve created a repeater field that it is generated by registering contacts. For example, my repeater field have the following sub fields:
– name
– email
– message
This is registered in a frontend form.
In my back of WordPress appears like this (chek the order):
– name 1, email 1, message 1
– name 2, email 2, message 2
– name 3, email 3, message 3
I want to add a filter that appears like this (automatically with the inverted order and for a specific custom post type called “Message Contact”):
– name 3, email 3, message 3
– name 2, email 2, message 2
– name 1, email 1, message 1
Please, can you help me?? Thanks
i don’t know if it is possible to filter at backend without one of this:
where you can order by ASC/DESC
if you have one of this field, than you can use this how-to to order your repeater
if it is only for frontend: than it is no need for such a field. just use something like this
$reversed = array_reverse($your_repeater);
Thanks for answer… ACF’ support commented me about array_reverse, too. Thye give me this code:
function my_acf_load_value( $value, $post_id, $field ) {
// bail early if no value
if( empty($value) ) {
return $value;
}
// return
return array_reverse($value);
}
add_filter(‘acf/load_value/name=my_repeater_field_name’, ‘my_acf_load_value’, 10, 3);
But appears the next error:
Warning: array_reverse() expects parameter 1 to be array, string given in C:\xampp\htdocs\new_useem_wp\wp-content\themes\useem\functions.php on line 203
In line 203:
return array_reverse($value);
What could be happening?
Thanks
I’m running into the exact same issue, I’ve noticed that $value is just a string equal to the number of rows I have saved in the repeater field.
Yes, I’ve put print_r($value) and it returns the number of rows. Ther should be some way that return the array of the rows…. but I dont know how
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
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.