Last active
December 16, 2015 15:19
-
-
Save aaroneaton/5454717 to your computer and use it in GitHub Desktop.
Getting one post from multiple categories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function query_features() { | |
global $query; | |
// Setup arguments for our query | |
$agencies = array( | |
'extension' => 'AgriLife Extension', | |
'research' => 'AgriLife Research', | |
'college' => 'College of Agriculture & Life Sciences', | |
'tfs' => 'Texas Forest Service', | |
'tvmdl' => 'TVMDL' | |
); | |
// Get the category ids from slugs | |
$cat_ids = $this->get_cat_id( $agencies ); | |
$cat_args = array( | |
'include' => $cat_ids, | |
'orderby' => 'name', | |
'order' => 'ASC' | |
); | |
$categories = get_categories( $cat_args ); | |
$slides = array(); | |
foreach( $categories as $cat ) { | |
$args = array( | |
'showposts' => 1, | |
'category__in' => $cat->term_id, | |
'caller_get_posts' => 1 | |
); | |
$post = get_posts( $args ); | |
setup_postdata( $post ); | |
$slides[] = array( | |
'img' => $this->get_thumb( $post[0]->ID ), | |
'caption' => $this->get_title( $post[0]->post_title ), | |
'permalink' => get_permalink($post[0]->ID), | |
'pubdate' => get_the_time( 'U', $post[0]->ID) | |
); | |
} | |
// Sort the slides array by 'pubdate' descending | |
usort($slides, array( $this, 'cmp' ) ); | |
return $slides; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment