doukucai0099 2010-01-07 21:38
浏览 40

WordPress:PHP:如何在类别中执行所需结果的嵌套排序

There is a plugin that I am trying to adapt for my meta_tags for use with WordPress. It is called Categories by Title by http://www.mikesmullin.com.

What I am trying to achieve is a nested sort. I have three meta_keys. A selection-no, release-month, and release-year. I would like to sort posts within their category by release-year (asc), release-month (asc), then selection-no (asc). For example: 1955 10 selection-no-1, 1956 10 selection-no-2, 1956 10 selection-no-5, and so on.

I have modified the code, however, it only sorts by the last meta_key listed, by release-year.

Here is the code.

add_action('pre_get_posts','sort_categories_by_title');

function sort_categories_by_title($x) {
if(is_category()) {
    $x->query_vars['orderby'] = 'meta_value';
    $x->query_vars['meta_key'] = 'selection-no';
    $x->query_vars['meta_key'] = 'release-month';
    $x->query_vars['meta_key'] = 'release-year';
    $x->query_vars['order'] = 'asc';
}
}

Any help would be greatly appreciated. Thank you.

  • 写回答

2条回答 默认 最新

  • doushi1964 2010-01-07 21:45
    关注

    Have a look at usort. You supply a comparison function which can look inside each item and choose what to order by.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题