Solved

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

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

Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

737 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