?
Solved

wordpress recent posts with category

Posted on 2014-04-16
7
Medium Priority
?
392 Views
Last Modified: 2014-05-01
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?
0
Comment
Question by:livewirewebsolutions
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40005584
Is this a wordpress.com site or a .org site?

If .org, which plugin are you using to get the shortcode?
0
 

Author Comment

by:livewirewebsolutions
ID: 40005589
its a wordpess site using the twenty twelve theme
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40005599
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?
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

Author Comment

by:livewirewebsolutions
ID: 40005617
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?
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40005645
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?
0
 

Author Comment

by:livewirewebsolutions
ID: 40005650
this is the link to the plugin: http://synved.com/wordpress-shortcodes/
0
 
LVL 15

Accepted Solution

by:
eemit earned 1320 total points
ID: 40006432
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).
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question