Sorry I am learning php, I don’t know where to place the “debug”
So far, still no change. Thank you.
Here is my function.php
<? function my_acf_load_value( $value, $post_id, $field ) {
$order = array();
if( empty($value) ) {
return $value;
}
foreach( $value as $i => $row ) {
$order[ $i ] = strtotime($row['field_5794d01d5c71a']);
}
array_multisort( $order, SORT_ASC, $value );
return $value;
print_r( get_field('programmation', field_5794d01d5c71a) );
}?>
<? add_filter('acf/load_value/key=field_5794d01d5c71a', 'my_acf_load_value', 10, 3);?>
Ok thank you for the explanation, here is what I achieve
<? function my_acf_load_value( $value, $post_id, $field ) {
$order = array();
if( empty($value) ) {
return $value;
}
foreach( $value as $i => $row ) {
$order[ $i ] = strtotime($row['field_5794d01d5c71a']);
}
array_multisort( $order, SORT_DESC, $value );
return $value;
}?>
<? add_filter('acf/load_value/key=field_5794d01d5c71a', 'my_acf_load_value', 10, 3);?>
So far, the order of the content doesn’t seem to change.
I can’t seem to find where the problem come from, any idea ?
Thank you very much @James
Hey @James, thank you for your help.
So I did try the following code you send me, it doesn’t seem to work yet.
Here is what I wrote on my functions.php
<? function my_acf_load_value( $value, $post_id, $field ) {
$order = array();
if( empty($value) ) {
return $value;
}
foreach( $value as $i => $row ) {
$order[ $i ] = strtotime($row['date']);
}
array_multisort( $order, SORT_DESC, $value );
return $value;
}?>
<? add_filter('acf/load_value/name=date', 'my_acf_load_value', 10, 3);?>
Hi @James
Thank you for your help, I’ve explored all your link.
To answer your question : I am trying to sort a repeater from a single page, so the current post I guess ?
I am trying to this (in the “Advanced” part).
A code that allow to sort front and backend.
https://www.advancedcustomfields.com/resources/how-to-sorting-a-repeater-field/.
So I use this code in my function.php
<? function my_acf_load_value( $value, $post_id, $field ) {
// vars
$order = array();
// bail early if no value
if( empty($value) ) {
return $value;
}
// populate order
foreach( $value as $i => $row ) {
$order[ $i ] = $row['date'];
}
// DATE is my time sub field.
// multisort
array_multisort( $order, SORT_DESC, $value );
// return
return $value;
}?>
<? add_filter('acf/load_value/name=scores', 'my_acf_load_value', 10, 3);?>
And I have the same code (the one that is in my question) on my template.php
Could you give me a hand ?
Hi, thanks for your help 🙂
So I did that, but doesn’t seem to work yet.
<?php
$post_object = array_reverse(get_field('relation'));
$post_object[0]
$repeater = get_field('repeater', $post_object->id);
$last_row = end($repeater);
$last_row['subhead'];
if( $post_object ):
// override $post
$post = $post_object;
setup_postdata( $post );
?>
<div>
<?php
// check if the flexible content field has rows of data
if( have_rows('selection') ):
// loop through the rows of data
while ( have_rows('selection') ) : the_row();
if( get_row_layout() == 'selectionselection' ):?>
<div class="titre-soustitre">
<div class="menu-content" data-id="id-<?php echo $post_object[0]['id']; ?>">
<p class="demo bis"><span class="sub"> </span></p>
<a href="#" class="expander"><h1><p class="demo title"><?php echo $post_object[0]['title'] ?></p></h1></a>
<p class="demo bis"><span class="sub"><?php echo $post_object[0]['subhead']; ?></span></p>
</div>
</div>
<?php endif;
endwhile;
else :
// no layouts found
endif;
?>
</div>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
I guess I should define the ID on the original flexible content ?
So far, the ID I use on the original flexible content are written by hand through a text field like this data-id="id-<?php the_sub_field('id');?>
Should I change that ?
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!
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.