• Hi, I’m trying to sort a custom column on the plugins.php page. Using the manage_plugins_custom_column action and the manage_{$this->screen->id}_sortable_columns filter. Getting the last_updated date from the plugins_api()

    After parsing the date with:

    human_time_diff( strtotime( $plugin_api->last_updated ) ) . ' ago';

    It’s loading fine and I get a “sortable” column. Except it’s not sorting. The content is changed to days, weeks, etc by the functions. Not sure what I need to do to make this sortable as it does not change any of the sorting. I tested it in another column and it worked great by sorting things alphabetically. I also notice that it sorts dates fine… I’d love for this to show the format I am setting by using human_time_diff() but also be able to sort it.

    Thanks for any thoughts you may have on this!

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The plugins list table isn’t sorted like the more common posts list table would be. There is no “wp_plugins_query” class to work with. Instead get_plugins() is used, which has no useful filters. However, there is the “all_plugins” filter you could use to re-sort the passed array of plugins. The problem is there is no direct tie to what’s happening with your sortable column. Your filter callback isn’t passed any information about what is happening with your column.

    When you click your column’s head, does it show up as an URL query string in the request? If it does, your filter callback could check $_REQUEST for that value and re-sort the passed array accordingly.

Viewing 1 replies (of 1 total)
  • The topic ‘Sorting custom column human_time_diff()’ is closed to new replies.