Solved

How would i add pages of post_type new to display in the Wordpress Recent Posts widget

Posted on 2014-04-08
2
749 Views
Last Modified: 2014-04-20
Hi

I am looking at the default widget for WP_Widget_Recent_Posts and i see this query
$r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) );

Open in new window


Is there any way i can modify this to include custom pages of post_type news as these have a featured images just like posts.

I could just write the query myself but I dont understand how the filters are being applied

Thanks a lot for any help you can give
0
Comment
Question by:andieje
2 Comments
 
LVL 15

Accepted Solution

by:
eemit earned 500 total points
ID: 39988529
Add this to your child theme's functions.php file:
add_filter( 'widget_posts_args', 'yourchildthemeslug_extend_recent_posts_query' );
function yourchildthemeslug_extend_recent_posts_query( $args ) {

	$args['post_type'] = array('post', 'yourcptslug'); //change 'yourcptslug' to your custom post type slug

	return $args;
}

Open in new window

Change 'yourchildthemeslug' to your child theme's slug.
If your child theme's slug contains hyphens, replace them here with underscores.
0
 

Author Closing Comment

by:andieje
ID: 40011386
Many thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now