dpr26232 2015-06-17 21:28
浏览 44
已采纳

根据数组中的时间戳存储发布数据

I have been trying to create a structural format of posts with the help of Wordpress get_posts function. The structure with I am creating is based on the post timestamps. So basically the posts having the same timestamps will be collected together and displayed on the page. The structure is something like

  1. TIMESTAMP (Example 12345678)

    POST 1 with timestamp 12345678

    POST 2 with timestamp 12345678

  2. TIMESTAMP (Example 87654321)

    POST 1 with timestamp 87654321

    POST 2 with timestamp 87654321

Now the approach I have been trying to achieve is to store the posts having similar timestamps in an array. So the array would be something like

array( $timestamp => array($post1, $post2) )

By this I think I will be able to get each post besides its timestamp and then I would just display the posts attached to a timestamp.

The problem is that I cannot store multiple values in the same timestamp and I am not sure if my code has problems or what.

THE CODE:

    foreach ($my_posts as $post) {

        // Get the current post details
        $post_id    = $post->ID;
        $post_title = get_the_title( $post_id  );
        $date       = get_post_meta( $post_id, 'timeline_event_date', true );

        // Change to format of the date ( Month Date, Year)
        $parsed = date_parse_from_format('n-d-Y', $date);
        $old_date_timestamp = mktime(
                $parsed['hour'], 
                $parsed['minute'], 
                $parsed['second'], 
                $parsed['month'], 
                $parsed['day'], 
                $parsed['year']
        );
        $new_date  = date('F j, Y', $old_date_timestamp);
        $post_unix_timestamp = strtotime($new_date);

        $eventHTML[] = array( $post_unix_timestamp => array( $post ) );

    }

Can somebody help me out here please? Thanks ..

  • 写回答

1条回答 默认 最新

  • duanmorong9597 2015-06-17 21:35
    关注

    Try to change this line

    $eventHTML[] = array( $post_unix_timestamp => array( $post ) );
    

    with this line

    $eventHTML[$post_unix_timestamp][] = $post;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败