post to post relationship is sorted by post_id, should be post_title

Support MB Admin Columns post to post relationship is sorted by post_id, should be post_title

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #17468
    molitor GmbHmolitor GmbH
    Participant

    Hello,

    I added a post-to-post relationship in my theme and wanted to sort the entries in the admin panel by the related post type's title. But instead, it sorts by the related post type's ID

    I tried to change it in the functions.php but due to my lag of WordPress-programming-experience I struggle to get it done.

    Here's my code so far:

    // Make admin columns sortable
     add_filter( 'manage_edit-exponat_sortable_columns', 'set_custom_exponat_sortable_columns' );
    
     function set_custom_exponat_sortable_columns( $columns ) {
       $columns['projekte_to_exponate_from'] = 'projekte_to_exponate_from';
    
       return $columns;
     }
    
     // Sorting rules for custom post types
     add_action( 'pre_get_posts', 'exponat_custom_orderby' );
    
     function exponat_custom_orderby( $query ) {
       if ( ! is_admin() )
         return;
    
       $orderby = $query->get( 'orderby');
    
       if ( 'projekte_to_exponate_from' == $orderby ) {
         $query->set( 'orderby', 'related_post_title' ); //I don't know how to do it correctly here
       }
     }

    How would I do it correctly?

    #17469
    molitor GmbHmolitor GmbH
    Participant

    Screenshot

    #17471
    molitor GmbHmolitor GmbH
    Participant

    Screenshot

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.