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?