How to change the default orderby from "Date" to e.g. "Title" or my custom column in content type records list in admin?

Right now the created or cahnged is always the first. But I want to order the records by my custom field (I already have created it with a sort functionality following the advice here: http://justintadlock.com/archives/2011/06/27/custom-columns-for-custom-post-types)

My question is how to set the orderby as default to e.g. title or my custom column called "expiration".

Is there any hook for that?

1 Answer 1


pre_get_posts the right hook you need to use.

function CPT_set_default_orderby($q){
    global $pagenow, $typenow;
    if( is_admin() && 'edit.php' == $pagenow && 'post' == $typenow && !isset($_GET['orderby']) ){

        // to order by title
        $q->set('orderby', 'title');

        // to orderby with meta key
        $q->set('orderby', 'meta_key');
        $q->set('meta_key', 'expiration');
add_action('pre_get_posts', 'CPT_set_default_orderby');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.