douhanzhen8927 2017-12-04 21:39
浏览 30

如何在WordPress中基于月份和日期对循环进行排序?

I have a loop that returns a list of birthdays. Currently, I'm using orderby => meta_value_num sort and it sorts year as well. See the code below:

            $today = date('d');
            $tomorrow = date('d', strtotime('+ 1 day'));
            $thedayaftertomorrow = date('d', strtotime('+ 2 day'));
            $current_month = date('m');
            $next_month = date('m', strtotime('+ 1 month'));
            $args = array (
              'posts_per_page' => 4,  // number of posts   
              'post_type'      => 'employees', // your custom post type
              'meta_key'       => 'birthday',  // your custom date field name
              'orderby'        => 'meta_value_num',
              'order'          => 'ASC',
              'meta_query' => array(
                'relation' => 'OR',
                array(
                  'key'      => 'birthday',
                  'compare'  => 'REGEXP',
                  'value'    => '[0-9]{4}' . $current_month . $today,
                ),
                array(
                  'key'      => 'birthday',
                  'compare'  => 'REGEXP',
                  'value'    => '[0-9]{4}' . $current_month . $tomorrow,
                ),
                array(
                  'key'      => 'birthday',
                  'compare'  => 'REGEXP',
                  'value'    => '[0-9]{4}' . $current_month . $thedayaftertomorrow,
                ), 
                array(
                  'key'      => 'birthday',
                  'compare'  => 'REGEXP',
                  'value'    => '[0-9]{4}' . $next_month . '[0-9]{2}',
                ),
              )
            );

Is there a way to ignore year and order by month and day? Date format I'm using is: Ymd

The code returns the following:

1990-12-01 1992-01-04 2001-03-04 2005-06-07

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么