Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Backend Custom post types orderby date - deprecated error WordPress


In my functions.php I have this code which is ordering the back-end posts properly:
I would like an alternative ordering so the error won't show up anymore.

//order back-end posts in date order
function set_custom_post_types_admin_order($wp_query) {
if (is_admin()) {
// Get the post type from the query
$post_type = $wp_query->query['post_type'];

if ( $post_type == 'events') {
add_filter('posts_orderby', 'post_date');
add_filter('pre_get_posts', 'set_custom_post_types_admin_order');

The faulty code should be this:

add_filter('posts_orderby', 'post_date');

The error message is:

Warning: call_user_func_array() []: First argument is expected to be a valid callback, 'post_date' was given in /home2/newporv0/public_html/wp-includes/plugin.php on line 220

For the additional error message, please click on the attachment image, where I had the debug message on.

Answers (3)


Michael Fields answers:

This worked for me. Please correct me if I am wrong, but aren't the posts already ordered by post_date?

function set_custom_post_types_admin_order( $q ) {
if ( is_admin() && isset( $q['post_type'] ) && 'events' === $q['post_type'] ) {
$q['orderby'] = 'post_date';
$q['order'] = 'ASC';
return $q;
add_filter( 'request', 'set_custom_post_types_admin_order' );

Lucian Florian comments:

Thanks Michael. It works well.
By default, were order by title.


Jonah Schulte answers:

What is the error message you're seeing?


MagoryNET answers:

In add_filter you are supposed to give a function name. You should write a function that returns 'post_date' and use it's name in place of 'post_date' in add_filter.

But.. in Wordpress 3.0 there is no longer such filter hook. You'll have to try if it still works.