Skip to content

Instantly share code, notes, and snippets.

@GoldenEra
Created May 5, 2015 01:57
Show Gist options
  • Save GoldenEra/146edeff2c1a1bbd339e to your computer and use it in GitHub Desktop.
Save GoldenEra/146edeff2c1a1bbd339e to your computer and use it in GitHub Desktop.
php: wordpress
/**
* [get_posts_by_slug description]
* @param [int] $num [number of posts you want to get]
* @param [string] $slug_name [slug's name]
* @return [array] [List of WP_Post objects.]
*/
function get_by_slug($num, $slug_name, $post_type = array('featured', 'social_post')){
if (!is_string($slug_name)) {
return false;
}
$args = array(
'category_name' => $slug_name,
'posts_per_page' => $num,
'post_type' => $post_type,
'post_status' => 'publish',
'offset' => 0
);
$posts = get_posts( $args );
return $posts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment