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
-
TIMESTAMP (Example 12345678)
POST 1 with timestamp 12345678
POST 2 with timestamp 12345678
-
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 ..