Created
February 9, 2016 19:31
-
-
Save jdcauley/da444d5835a2524d6228 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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