Created
May 5, 2015 01:57
-
-
Save GoldenEra/146edeff2c1a1bbd339e to your computer and use it in GitHub Desktop.
php: wordpress
This file contains 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
/** | |
* [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