I want to use the menu order
attribute to control ordering for a custom post type that’s going to be used for a specific purpose.
It’s easy enough to add this to the CPT via supports => array('page-attributes')
but how do I expose the menu order value on the admin listing screen for this CPT?
OK – in the end turned out to be fairly simple – as I’d had some kind of mental block –
menu_order
is a variable in the$post
object (thanks to @brady for reminding me of that).@scribu’s post on creating sortable column values then gives the rest.
So, assuming the custom post type is called
header_text
, these are the functions and hooks that are needed:Add a new column for the order
Render the column values
Set the column to be sortable
It’s been too long, but just for the record, you can display the ‘menu order’ option in the admin, just by including ‘page-attributes’ in the ‘supports’ option array. For example:
@anu let me to the right direction, however that is not a modern code
Modern solution && working on WordPress 5.4
…
If you are interested how would you make sortable column that is not based on some basic Query variable you would play around
request
filter as described in documentation here: https://make.wordpress.org/docs/plugin-developer-handbook/10-plugin-components/custom-list-table-columns/#sortable-columnsYou have to register your CPT with: