Skip to content

Instantly share code, notes, and snippets.

@jdcauley
Created February 9, 2016 19:31
Show Gist options
  • Select an option

  • Save jdcauley/da444d5835a2524d6228 to your computer and use it in GitHub Desktop.

Select an option

Save jdcauley/da444d5835a2524d6228 to your computer and use it in GitHub Desktop.
function get_menu_posts(){
if($data = get_transient('menu_posts')){
return $data;
} else {
$menu_posts = new stdClass;
$categories = array(57,56,55,1734,20,21,23,1716,1717,39,1718);
foreach($categories as $category){
$cat_info = get_category($category);
$posts = get_posts(array(
'posts_per_page' => 4,
'category' => $category
));
$name = str_replace(' ', '_', $cat_info->name);
$name = str_replace('&', '', $name);
$everything = new stdClass;
$everything->category = $cat_info;
$everything->posts = $posts;
$menu_posts->$name = $everything;
wp_reset_postdata();
}
set_transient('menu_posts', $menu_posts, 3600);
return $menu_posts;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment