Slider Revolution WP
09.06.2016
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
add_filter('essgrid_query_caching', 'eg_stop_caching', 10, 2); add_filter('essgrid_modify_posts', 'eg_modify_post', 10, 2); // turn off caching for your grid function eg_stop_caching($do_cache, $grid_id) { // [ 1 ] enter your grid's ID here // https://www.themepunch.com/wp-content/uploads/2015/03/grid-id.jpg $grid_id = 36; if($grid_id == $grid_id) return false; return true; } function eg_modify_post($posts, $id){ // [ 2 ] enter your grid's ID here // https://www.themepunch.com/wp-content/uploads/2015/03/grid-id.jpg $grid_id = 36; // [ 3 ] list of category IDs to grab recent posts from // https://tinyurl.com/jfzeqrk $categories = array(29, 30); // [ 4 ] number of recent posts from each category $numPerCategory = 4; // [5] choose to randomize the order of all entries $randomizeItems = true; /* no need to edit below */ if($grid_id != $id) return $posts; $filterPosts = array(); // https://codex.wordpress.org/Function_Reference/wp_get_recent_posts $args = array( 'numberposts' => $numPerCategory, 'offset' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' =>'', 'post_type' => 'post', 'post_status' => 'publish', 'suppress_filters' => true ); foreach($categories as $category) { $args['category'] = $category; $recentPosts = wp_get_recent_posts($args); foreach($recentPosts as $recentPost) { $filterPosts[] = $recentPost; } } if(!$randomizeItems) return $filterPosts; $keys = array_keys($filterPosts); $randomPosts = array(); shuffle($keys); foreach($keys as $key) $randomPosts[$key] = $filterPosts[$key]; return $randomPosts; } |