5 Replies to “How To Make Your WordPress Admin Columns Sortable”

  1. Hi Rachel,
    I’ve created a custom column displayed in the Users section of wp-admin, which lists their post count of a custom post type. I was wondering if you knew how I would then sort that data? All of the examples I’ve found on the net refer to sorting data by a meta value, but your second example of sorting by date look like it could be adapted to my needs. Unfortunately I’m not so great at SQL queries so I’m not quite sure how to do it. I’ve asked a question on wordpress stackexchange ( http://wordpress.stackexchange.com/questions/152494/make-a-custom-column-sortable-by-custom-post-count ) which has the code in more detail. It would be great if you could help out.
    Thanks!

  2. Vuepoint Creative says:

    Rachel I have a single column that is made up of two meta_key values. A date custom field and a time custom field (I didn’t create this structure because I would have otherwise made the date and time field just one custom field). The two fields make up the column data in the form of August 4, 2014 2:00pm and the string of numbers in the database per field are similar to this obviously: (Date: 234950495 Time: 30839) How can I use your orderby function with two separate fields that need to be combined prior to sorting? Is it possible to use the already combined date instead of requerying? Please let me know if that doesn’t make sense.
    P.S. The two keys in postmeta are cro_date and cro_time.
    Danny

  3. Rachel
    Thank you for this great stuff, but are you missing “return $sortable_columns;” from your first snippet above? It is in your GitHub code.

  4. Marc Versluis says:

    Hi Rachel,
    I created a custom column for my custom post type and populated the column with data from a custom field. I’m struggling to get Option B working because I use the Advanced Custom Fields plugin to store release dates in a custom field. Values from the custom field are retrieved with get_field( “release_date” ). Could you give a hint on how to adapt your code for Option B?
    http://www.advancedcustomfields.com/resources/get_field/
    Kind regards, Marc

Leave a Reply

Your email address will not be published. Required fields are marked *