admin管理员组文章数量:1420120
I have a custom post type called 'Courses'. I'm currently trying to automatically display them in the dashboard 'Courses' post list sorted by a date value specified in a custom field.
The date value is saved in d-m-Y format.
Using the code below I am able to sort the posts, but they are incorrectly ordered by the first number in the full date string (ie. the '01' in '01-12-19'), rather than the date.
function display_custom_posts_sorted_by_date($query) {
if (is_admin()) {
if (isset($query->query_vars['post_type'])) {
if ($query->query_vars['post_type'] == 'courses') {
$query->set('meta_key', 'online_start');
$query->set('orderby', 'meta_value');
$query->set('order', 'DESC');
}
}
}
}
add_filter('pre_get_posts' , 'display_custom_posts_sorted_by_date');
I already have functionality in place to manually sort the post list using a filterable column, discussed here - How to Sort by Date When Using d-m-Y Format
Is it possible to amend the 'meta_key' query in the function above so that it recognizes the d-m-Y date format?
本文标签: orderWordPress AdminAutomatically Sort Custom Posts by Custom Field Date Value in dmY Fomat
版权声明:本文标题:order - WordPress Admin - Automatically Sort Custom Posts by Custom Field Date Value in d-m-Y Fomat 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745327446a2653657.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论