php - Sorting Array of Categories -
i'm attempting sort following array use in foreach loop outputs latest post each of categories of goose-creek, sleepy-creek, , fobr.
i want sort array post date, i'm confused on how accomplish this. better add multiple categories wp_query args , remove foreach loop?
$feed_sources = array('goose-creek','sleepy-creek','fobr'); foreach ($feed_sources $feed) { $args = array('category_name' => $feed, 'posts_per_page' => 1); $show = new wp_query($args); $show->the_post();
the following code uses associative array , outputs category key , date integer value.
arsort() sorts array high low
$feed_sources = array('goose-creek','sleepy-creek','fobr'); $dates_array = array(); foreach ($feed_sources $feed) { $args = array('category_name' => $feed, 'posts_per_page' => 1); $show = new wp_query($args); $show->the_post(); $dates_array[$feed] = the_date('ymdhis','','',false); } arsort($dates_array); $ordered_sources = array_keys($dates_array); foreach ($ordered_sources $feed) { $args = array('category_name' => $feed, 'posts_per_page' => 1); $show = new wp_query($args); $show->the_post();
Comments
Post a Comment