wordpress recent posts with category

i am using the shortcode [recent-posts] on a page and its working perfectly.  However, instead of all posts appearing, I want only posts from a certain category to appear.  How do I code this?
Who is Participating?
eemitConnect With a Mentor Commented:
Try this in your theme's functions.php:
add_filter( 'widget_posts_args', 'yourchildthemeslug_extend_recent_posts_query' );
function yourchildthemeslug_extend_recent_posts_query( $args ) {
	$args['category__in'] = array('2'); //change '2' to your category ID
	//use this to show posts from more categories
	//$args['category__in'] = array('2', '3'); //change '2' and '3' to your category IDs

	return $args;

Open in new window

Change 'yourchildthemeslug' to your child theme's slug.
If your child theme's slug contains hyphens, replace them with underscores (You can not use a hyphen in a PHP function name).
Jason C. LevineNo oneCommented:
Is this a wordpress.com site or a .org site?

If .org, which plugin are you using to get the shortcode?
livewirewebsolutionsAuthor Commented:
its a wordpess site using the twenty twelve theme
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Jason C. LevineNo oneCommented:
Haven't answered my questions.

Is this self hosted or hosted through wordpress.com? Twenty Twelve exists on both.

If self hosted, which plugins are installed?
livewirewebsolutionsAuthor Commented:
self hosted.  wordpress shortcodes plugin is installed but i don't think its the reason why [recent-posts] works.  Doesn't that shortcode come with Wordpress?
Jason C. LevineNo oneCommented:
Doesn't that shortcode come with Wordpress?

Nope :)

Self-hosted WordPress doesn't come with any shortcodes out of the box...they are added in by coding, themes, and plugins.  Wordpress.com is a different story. Which shortcode plugin is this...there are two or three people who make one?
livewirewebsolutionsAuthor Commented:
this is the link to the plugin: http://synved.com/wordpress-shortcodes/
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.