Home Forums Add-ons Repeater Field Sort a repeater field – error – Notice: Undefined index: field


Sort a repeater field – error – Notice: Undefined index: field

  • Hi,

    I have a problem with sorting arrays inclouding sub_field. I read similar topics, but I don’t find solution. I used the second example (I used code in functions.php file) from this

    this is the file with acf rows and fields:

    $the_query = new WP_Query( $args );  
    	if ( $the_query->have_posts() ) :
    	while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
            <div class="cv_title-wrap">
                <h2 class="cv_title"><?php the_title();  ?></h2>  
                <div class="title-line"></div>
            <div class="cv_content">
                <table class="content_table" >
                    <?php if(have_rows("cv_row")): ?>
                    <?php while(have_rows("cv_row")) : the_row();?>
                            <td class="cv_subtitle"><?php the_sub_field("cv_years") ?></td>
                            <td class="cv_description"><?php the_sub_field("cv_achievements") ?></td>
                    <?php endwhile; ?>
                    <?php endif; ?>
    	else: esc_html_e( 'Nie ma postów spełniających dane kryteria', 'text-domain' );

    and it is code in functions.php. file

    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['field_5e1a03262c898'];
    	// multisort
    	array_multisort( $order, SORT_DESC, $value );
    	// return	
    	return $value;
    add_filter('acf/load_value/name=cv_row', 'my_acf_load_value', 10, 3);

    and this is error message:

    Notice: Undefined index: field_5e1a03262c898 in C:\xampp\htdocs\template\wp-content\themes\theme_name\functions.php on line 30

    the key(field_5e1a03262c898) is correct . I don’t know how to fix this error

    I use ACF pro in 5.8.7. version

    could you help me please?
    ps. sorry for my english

  • I understand where I made a mistake.
    this key: field_5e1a03262c898 should refer to the field after which we iterate.
    and this filed name add_filter('acf/load_value/name=<strong>cv_row</strong>' ... should refer to row.

  • no

    add_filter('acf/load_value/name=<strong>cv_row</strong>' ...


    add_filter('acf/load_value/name=cv_row' ...

    by filename I meant cv_row

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

The topic ‘Sort a repeater field – error – Notice: Undefined index: field’ is closed to new replies.