WPIntell

Source evidence

Add sort function to column (fix attached ;))

Admin Slug Column · support · 2024-11-13T15:19:00+00:00

mixedsentiment
mediumseverity
0.78relevance
2replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

4 / 18 rows with source links

22.2% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

14 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
Caged resolved
Hey there, in one of the reviews i saw another user (@florisassies) suggesting to include a sort function. Now i’m no coder but i asked ChatGPT and it tweaked the plugin and it works. <?php /** * Admin Slug Column (Streamlined Version) * * @package Admin_Slug_Column_Simplified * @wordpress-plugin * Plugin Name: Admin Slug Column (Streamlined) * Description: Adds a sortable "Slug" column to the admin posts/pages list without additional columns. * Version: 1.0 * Author: Adapted Plugin */ // If this file is called directly, abort if ( ! defined( 'WPINC' ) ) { die; } // Only run plugin in the admin if ( ! is_admin() ) { return; } // Add slug column to admin posts/pages lists function add_slug_column($columns) { $columns['slug'] = __('Slug'); return $columns; } add_filter('manage_posts_columns', 'add_slug_column'); add_filter('manage_pages_columns', 'add_slug_column'); // Populate slug column with the post slug function display_slug_column_content($column, $post_id) { if ($column === 'slug') { $post = get_post($post_id); echo esc_html($post->post_name); // Display the post slug } } add_action('manage_posts_custom_column', 'display_slug_column_content', 10, 2); add_action('manage_pages_custom_column', 'display_slug_column_content', 10, 2); // Make slug column sortable function add_slug_column_sortable($columns) { $columns['slug'] = 'slug'; return $columns; } add_filter('manage_edit-post_sortable_columns', 'add_slug_column_sortable'); add_filter('manage_edit-page_sortable_columns', 'add_slug_column_sortable'); // Modify the query to sort by slug when requested function sort_by_slug_column($query) { if (!is_admin() || !$query->is_main_query()) { return; } $orderby = $query->get('orderby'); if ('slug' == $orderby) { $query->set('orderby', 'name'); // 'name' represents the slug in the database } } add_action('pre_get_posts', 'sort_by_slug_column'); HAH… love that effort. There’s an issue for this from way back; the last “it works” didn’t. I do have a small refactor I’m slowly working on and I’ll look at this issue again. Feel free to add a comment to https://github.com/chuckreynolds/Admin-Slug-Column/issues/13 and see what I can do. Thanks! @ryno267 Thanks. I pasted the code in the Github issue. Good luck and thanks for the work you have already put into this plugin.

Comments

2 shown
Chuck Reynolds 2024-11-13T19:16:00+00:00

HAH… love that effort. There’s an issue for this from way back; the last “it works” didn’t. I do have a small refactor I’m slowly working on and I’ll look at this issue again. Feel free to add a comment to https://github.com/chuckreynolds/Admin-Slug-Column/issues/13 and see what I can do. Thanks!

Caged 2024-11-14T09:04:00+00:00

@ryno267 Thanks. I pasted the code in the Github issue. Good luck and thanks for the work you have already put into this plugin.