/** * Get post by category * * @return Mixed $collection of grid objects */ public static function category() { $id = get_the_category()[0]->cat_ID; $posts = get_posts(['numberposts' => 3, 'category' => $id, 'post_type' => 'post', 'post_status' => 'publish', 'suppress_filters' => true]); return Grid::build($posts); }
/** * Get post by tag * * @return Mixed $collection of grid objects */ public static function get() { $tag = get_terms('post_tag', 'include=' . get_query_var('tag_id'))[0]->slug; $posts = get_posts(['numberposts' => 3, 'tag' => $tag, 'post_type' => 'post', 'post_status' => 'publish', 'suppress_filters' => true]); return Grid::build($posts); }
/** * Get post by search query * * @return Mixed $collection of grid objects */ public static function get() { $s = get_search_query(); $posts = get_posts(['numberposts' => 3, 's' => $s, 'post_type' => 'post', 'post_status' => 'publish', 'suppress_filters' => true]); return Grid::build($posts); }