Skip Navigation

[Resolved] Add post relationship column to custom post list in admin / Make it sortable

This support ticket is created 6 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by koheiY 6 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#924476

This is a continued topic below;
https://toolset.com/forums/topic/add-post-relationship-column-to-custom-post-list-in-admin-menu-child-post-count/
https://toolset.com/forums/topic/add-post-relationship-column-to-custom-post-list-in-admin-menu/

Thanks to your kind support, I can add post relationship column to custom post list in admin.

Next time, I want to make these colomns sortable.
I added "manage_edit-[post-type]_sortable_columns" to the previous codes.

/******************************
 ** Adds post relationship column to shops table
 ******************************/
add_filter( 'manage_edit-shops_columns', 'my_edit_shops_columns' ) ;
add_filter( 'manage_edit-shops_sortable_columns', 'my_edit_shops_columns' ) ;
function my_edit_shops_columns($defaults) {
    $defaults['parent'] = 'Parent';
    return $defaults;
}
  
/******************************
 ** Adds data to the post relationship column in shops table
 ******************************/
add_action( 'manage_shops_posts_custom_column', 'my_manage_shops_columns', 10, 2 );
function my_manage_shops_columns($column_name, $post_id) {
    if ($column_name == 'parent') {
            echo do_shortcode("[wpv-post-title item='@salons-shops.parent']");
            } 
    }


/******************************
 ** Adds post relationship column to salons table
 ******************************/
add_filter( 'manage_edit-salons_columns', 'my_edit_salons_columns' ) ;
add_filter( 'manage_edit-salons_sortable_columns', 'my_edit_salons_columns' ) ;
function my_edit_salons_columns($defaults) {
    $defaults['child'] = 'Child';
    return $defaults;
}
   
/******************************
 ** Adds data to the post relationship column in salons table
 ******************************/
add_action( 'manage_salons_posts_custom_column', 'my_manage_salons_columns', 10, 2 );
function my_manage_salons_columns($column_name, $post_id) {
    if ($column_name == 'child') {
            $children = toolset_get_related_posts(
              $post_id,
              'salons-shops',
              'parent',
              1000000,
              0,
              array(),
              'post_id',
              'child'
            );
    echo sizeof($children);
    } 
}

After I added the codes, the columns ”Parent” and ”Child” changed to be clickable.

But after clicking it, I found it didn't works correctly.
How should I modify the codes?

#947808

Unfortunately there is not a simple solution available that will support sortable columns. It will require significantly more custom code than supporters will provide here in the forums. You may be able to get assistance from a skilled developer in our Contractors portal, who can add custom column sorting features for you: https://toolset.com/contractors
Or, feel free to add a new ticket here in the forum using the "Suggest an improvement" option. Describe what you would like and our developers will evaluate the request.

#948206

I added a new ticket using the "Suggest an improvement" option.
Thank you for your support.