dongyou6768 2013-09-23 22:17
浏览 98

按一个自定义字段对Wordpress帖子进行排序,同时排除所有其他值

i have my wordpress posts with two custom fields 'episode_number' 'season_number'

i want to select all posts with season_number=5(example) , and sort them by episode_number DESC

i've written this

            $max_season=5;
            $args = array(
            'meta_key' => 'season_number',
            'meta_compare' =>'==',
            'meta_value' => $max_season,
            'orderby' => 'episode_number',
            'order' => 'DESC',
        );
$wp_query = new WP_Query($args);

the selection based on season_number works , but i can't order them , with this code wordpress order them based on the time of publishing

anyone can help me?

  • 写回答

2条回答 默认 最新

  • doutao5499 2013-09-23 22:25
    关注

    My original answer was off the mark, I misread the question

    Try something like this:

    $max_season=5;
    $args = array(
        'meta_key' => 'episode_number',
        'orderby' => 'meta_value_num',
        'order' => 'DESC',
        'meta_query' => array(
            array(
            'key' => 'season_number',
            'value' => array($max_season),
            'compare' => 'IN',
            )
       )
    );
    $wp_query = new WP_Query($args);
    
    评论

报告相同问题?

悬赏问题

  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写