logo

$5
Backend Custom post types orderby date - deprecated error

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() [function.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.

attachment image View Attachment

Lucian Florian | 10/18/10 at 12:22pm | Edit


(3) Possible Answers Submitted...

  • avatar
    Last edited:
    10/18/10
    12:28pm
    Jonah Schulte says:

    What is the error message you're seeing?

  • avatar
    Last edited:
    10/18/10
    12:46pm
    MagoryNET says:

    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.

    Previous versions of this answer: 10/18/10 at 12:40pm | 10/18/10 at 12:43pm | 10/18/10 at 12:43pm | 10/18/10 at 12:46pm

  • avatar
    Last edited:
    10/18/10
    12:52pm
    Michael Fields says:

    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' );

    Previous versions of this answer: 10/18/10 at 12:47pm | 10/18/10 at 12:51pm

    • 10/18/10 12:51pm

      Lucian Florian says:

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

This question has expired.





Current status of this question: Completed