I have custom post type “books” and there are already ‘books’ added.
However, I am unable to modify WP_Query to change Recent Posts widget.
I know that there is filter to modify WP_Query args:
add_filter( 'widget_posts_args', 'wp130512_recent_posts_args');
function wp130512_recent_posts_args($args) {
$args['post_type'] = array('post', 'books');
return $args;
}
But unforutunately this doesn’t work. I have even tried to mdoify default-widgets.php (just for test) directly and it doesn’t show any ‘books’ (just ‘posts’).
I even have tried to add this code (just for test) into default-widgets.php, but it shows nothing. If I add the exect code to my front page (front-page.php), then it shows “books”.
<?php
$queryObject = new WP_Query( 'post_type=books&posts_per_page=5' );
// The Loop!
if ($queryObject->have_posts()) {
?>
<ul>
<?php
while ($queryObject->have_posts()) {
$queryObject->the_post();
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
}
?>
</ul>
<div><a href="#">View More</a></div>
<?php
}
?>
So, what is the reason I cannot get custom post types inside this widget?
Read more here: Unable to shoe recent custom post types in default recent posts widget