Solved

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

Posted on 2014-04-08
2
756 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
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 count occurrences of each item in an array.

791 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