Support

Account

Home Forums General Issues Relationship Field – Post Order

Solved

Relationship Field – Post Order

  • I’m attempting to order the posts in a relationship field by date, newest to oldest, instead of the default alphabetical order:

    function my_relationship_query( $args, $field, $post_id ) {
    	
      $args = array(
        'orderby' => 'date',
        'order'   => 'DESC',
        'post_status' => 'publish'
      );
      return $args;
        
    }
    add_filter('acf/fields/relationship/query', 'my_relationship_query', 10, 3);

    This works as intended, but breaks the search functionality. Is there any way to achieve this without breaking the search function?

    Thanks,
    Dan

  • Sorry, answering my own question with an (obvious) answer. In case anyone else is interested:

    function my_relationship_query( $args, $field, $post_id ) {
    	
      $args['orderby'] = 'date';
      $args['order'] = 'DESC';
      $args['post_status'] = 'publish';
      return $args;
        
    }
    add_filter('acf/fields/relationship/query', 'my_relationship_query', 10, 3);
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Relationship Field – Post Order’ is closed to new replies.