wordpress后台通过register_post_type自定义文章类型排序

2023-05-0209:51:46后端程序开发Comments5,134 views字数 324阅读模式

wordpress后台通过register_post_type自定义文章类型排序文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/38219.html

发现wordpress通过register_post_type自定义文章类型后,在定义的分类中写文章,文章并没有按照最新时间排序,于是将此调整了一下,调整代码如下文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/38219.html

function doc_post_order( $wp_query )
{
if (is_admin())
{
$post_type = $wp_query->query['post_type'];
if( $post_type == 'doc')
{
$wp_query->set('orderby', 'date');
$wp_query->set('order', 'DESC');
}
}
}
add_filter('pre_get_posts', 'doc_post_order');
复制代码

这样就可以实现按照文章排序啦。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/38219.html

文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/38219.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/bc/38219.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定