Support

Account

Home Forums ACF PRO How-to change order of related listing

Solved

How-to change order of related listing

  • Hi,

    I like to reverse the list of “related” listing from newer to older in the WP back-office’s post display.

    There is a way to chose to display ASC or DESC listing (back-office not front) of related ? Maybe a setting in the future ?

    thanks,
    Mike

  • Hi @supersonique

    Could you please tell me about this “related” listing? Do you mean relationship field? If it is, you can modify the values returned by relationship field using acf/fields/relationship/query.

    If that isn’t what you mean, could you please provide me with some screenshots?

    Hope this helps.

  • Thanks for the feedback @james, please find attached a screenshot + note

    I like display related posts who are listed in post edit interface from the newest entry to oldest (currently from oldest to newest by default).

    Is the filters given as examples will modify the post edit interface listing display ?

    Cheers,
    Mike

  • Hi @supersonique

    Yes, that hook is used to modify the returned post on relationship field. I believe you can use something like this:

    function my_relationship_query( $args, $field, $post_id ) {
    
        // only show children of the current post being edited
        $args['orderby'] = 'date';
        $args['order'] = 'DESC'; //change this to ASC or DESC
    
        // return
        return $args;
        
    }
    
    // filter for every field
    add_filter('acf/fields/relationship/query/name=my_relationship', 'my_relationship_query', 10, 3);

    Hope this helps!

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

You must be logged in to reply to this topic.