0

I've created a custom column. Currently they are automatically sorting by title however i want them to sort by date. I've tried adding a "query_post" like:

query_posts('&post_type=project&orderby=date');

This sorts the list correctly but now only shows the current months posts and I can't query anything else like filter by date or view trash?!

Could someone kindly guide me in the right direction.

Thanks so much :)

.

My code:

add_filter('manage_edit-project_columns', 'add_new_project_columns');
function add_new_project_columns($project_columns) {

    // custom columns //
    $new_columns['cb'] = '<input type="checkbox" />';
    $new_columns['images'] = _x('Featured Image');
    $new_columns['title'] = _x('Title');
    $new_columns['projectcategories'] = _x('Filters');
    $new_columns['date'] = _x('Date');

    // Query posts to show date first *NOT WORKING AS DESIRED* //
    query_posts('&post_type=project&orderby=date');

    return $new_columns;
}
1
  • Can anyone help? Do I need to explain it better?
    – Jammer
    Commented May 1, 2015 at 4:35

1 Answer 1

0

After a lot of guess work and research I've managed to come up with a simple solution.

function column_orderby( $vars ) {
    $vars['orderby'] = 'date';
    $vars['order'] = 'desc';
    return $vars;
}
add_filter( 'request', 'column_orderby' );

This will sort all of the columns by 'date' as well as order them by 'desc'!

Hope it helps anyone in the same situation as me :)

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