Hi all I am new in php and I need yor help.
I do something in wordpress I create posts and with advanced custom field i write date in every post so I need to sort array of posts from max to min taking custom fields dates how can I do that?
my code
<?php
$args = array(
'post_type' => 'events',
'posts_per_page' => -1,
);
$posts_array = get_posts($args); posts array;
/// need some sort function
/// for taking post field date get_field("date", $posts_array[0]->ID);
////echo date from posts array
foreach ( $posts_array as $post ) : setup_postdata( $post );
$category_Post_Id=$post->ID;
$date = get_field("date", $category_Post_Id);
echo $date . ", ";
?>
<?php endforeach; ?>
thanks for your help
dump
array(4) {
[0]=>
object(WP_Post)#123 (24) {
["ID"]=>
int(17)
["post_author"]=>
string(1) "1"
["post_date"]=>
string(19) "2015-07-09 08:36:04"
["post_date_gmt"]=>
string(19) "2015-07-09 08:36:04"
["post_content"]=>
string(23) "asfasdfasdfasdfasdfasdf"
["post_title"]=>
string(8) "events-4"
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(4) "open"
["ping_status"]=>
string(4) "open"
["post_password"]=>
string(0) ""
["post_name"]=>
string(8) "events-4"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2015-07-09 08:36:31"
["post_modified_gmt"]=>
string(19) "2015-07-09 08:36:31"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(50) "http://localhost/lorig/?post_type=events&p=17"
["menu_order"]=>
int(0)
["post_type"]=>
string(6) "events"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
[1]=>
object(WP_Post)#293 (24) {
["ID"]=>
int(15)
["post_author"]=>
string(1) "1"
["post_date"]=>
string(19) "2015-07-09 08:34:03"
["post_date_gmt"]=>
string(19) "2015-07-09 08:34:03"
["post_content"]=>
string(10) "eatsdfasdf"
["post_title"]=>
string(8) "events-3"
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(4) "open"
["ping_status"]=>
string(4) "open"
["post_password"]=>
string(0) ""
["post_name"]=>
string(8) "events-3"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2015-07-09 08:34:03"
["post_modified_gmt"]=>
string(19) "2015-07-09 08:34:03"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(50) "http://localhost/lorig/?post_type=events&p=15"
["menu_order"]=>
int(0)
["post_type"]=>
string(6) "events"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
[2]=>
object(WP_Post)#294 (24) {
["ID"]=>
int(13)
["post_author"]=>
string(1) "1"
["post_date"]=>
string(19) "2015-07-09 08:33:37"
["post_date_gmt"]=>
string(19) "2015-07-09 08:33:37"
["post_content"]=>
string(13) "afsdfasdfasdf"
["post_title"]=>
string(8) "events-2"
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(4) "open"
["ping_status"]=>
string(4) "open"
["post_password"]=>
string(0) ""
["post_name"]=>
string(8) "events-2"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2015-07-09 08:33:37"
["post_modified_gmt"]=>
string(19) "2015-07-09 08:33:37"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(50) "http://localhost/lorig/?post_type=events&p=13"
["menu_order"]=>
int(0)
["post_type"]=>
string(6) "events"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
[3]=>
object(WP_Post)#295 (24) {
["ID"]=>
int(11)
["post_author"]=>
string(1) "1"
["post_date"]=>
string(19) "2015-07-09 08:33:10"
["post_date_gmt"]=>
string(19) "2015-07-09 08:33:10"
["post_content"]=>
string(15) "sdfsdfsdfsdfsdf"
["post_title"]=>
string(8) "events 1"
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(4) "open"
["ping_status"]=>
string(4) "open"
["post_password"]=>
string(0) ""
["post_name"]=>
string(8) "events-1"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2015-07-09 08:33:10"
["post_modified_gmt"]=>
string(19) "2015-07-09 08:33:10"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(50) "http://localhost/lorig/?post_type=events&p=11"
["menu_order"]=>
int(0)
["post_type"]=>
string(6) "events"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
}