Support

Account

Home Forums Front-end Issues sorting entries in repeater post object field Reply To: sorting entries in repeater post object field

  • Hi @rudtek

    The strolower() function is used to make the sorting insensitive.

    If you want to sort the repeater, then you need to use the “session.” But if you want to sort the post object, then it should be “session_speaker.” I haven’t tested it with your setup, but it’s working on my post object field. Could you please share the JSON export file of your field group so I can test it up on my installation?

    Also, could you please debug it like this:

    function my_acf_sort_post_object( $value, $post_id, $field ) {
    	
    	// vars
    	$order = array();
    	
    	// bail early if no value
    	if( empty($value) ) {
    		return $value;	
    	}
    	
    	// populate order
    	foreach( $value as $i => $post_id ) {
            $post_title = get_the_title($post_id);
    		$order[ $i ] = $post_title;
    	}
        
        echo "<pre>";
        print_r($value);
        echo "</pre>";
        
        echo "<pre>";
        print_r($order);
        echo "</pre>";
        
        $order_lowercase = array_map('strtolower', $order);
    	
    	// multisort
    	array_multisort( $order_lowercase, SORT_ASC, SORT_STRING, $value );
    	
    	// return	
    	return $value;	
    }
    
    add_filter('acf/load_value/name=session_speaker', 'my_acf_sort_post_object', 10, 3);

    And on the front end, just execute the get_field() function like this:

    get_field('session_speaker');

    Thanks 🙂