I run a loop for posts, these have a date field but this is a string, so I first order by date using a function, and it works. But I am missing the ID and I need to associate both the date with its ID as I will then need to run a loop over these ids and have the posts be ordered by dates. So I thought of using a multidimensional array but not a php here
$queryPosts = new WP_Query(array(
'posts_per_page' => -1,
'post__in' => $postIds,
)
);
if( $queryPosts->have_posts() ):
$dateOrdered = [];
while ( $queryPosts->have_posts() ) : $queryPosts->the_post();
$id = $post->ID;
$dateOrdered[] = usp_get_meta(false, 'usp-custom-80');
endwhile;
endif;
function custom_sort_dt($a, $b) {
return strtotime($a) - strtotime($b);
}
usort($dateOrdered, "custom_sort_dt");
print_r($dateOrdered);
I am expecting an arrays of IDs