$5
Backend Custom post types orderby date - deprecated error
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.
Lucian Florian | 10/18/10 at 12:22pm
| Edit
(3) Possible Answers Submitted...
-

Last edited:
10/18/10
12:28pm -

Last edited:
10/18/10
12:46pmMagoryNET 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
-

Last edited:
10/18/10
12:52pmMichael 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.
- 10/18/10 12:51pm
This question has expired.
Current status of this question: Completed





