How to display recent posts added in several custom post types

You can pass multiple custom post types in an array for ‘post_type’, as in: ‘post_type’ => array(‘books’, ‘stories’, ‘movies’) Your code seems to try to do this, but the syntax is a bit off, it should be: $recent_posts = wp_get_recent_posts( array( ‘post_type’ => array( ‘books’, ‘stories’, ‘movies’ ), ) ); You can find more details … Read more

If numberposts = -1 offset won’t work

This problem has pretty simple explanation 😉 All you need to do is to take a look at Codex page for WP_Query and read about offset parameter: offset (int) – number of post to displace or pass over. Warning: Setting the offset parameter overrides/ignores the paged parameter and breaks pagination (Click here for a workaround). … Read more

customizing recent posts

Inside your post loop: <div class=”recent-post”> <div class=”thumbnail”> <?php if(has_post_thumbnail()) { the_post_thumbnail(); } else { // show a default image if no featured image is specified echo ‘<img src=”‘.get_bloginfo(“template_url”).’/images/img-default.png” />’; } ?> </div> <div class=”title”> <a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a> </div> </div> float the thumbnail div to the left and give the title div … Read more

How to hide a post from ‘Recent Posts’ widget?

You can exclude posts from the recent posts widget via the widget_posts_args filter: add_filter( ‘widget_posts_args’, ‘exclude_posts_wpse_103570’); function exclude_posts_wpse_103570( $args ){ // post ID’s to exclude: $args[‘post__not_in’] = array( 123, 234, 345 ); return $args; }

Show recent published posts

The arguments you are using are wrong. They should be: $args = array( ‘numberposts’ => ’10’, ‘post_type’ => ‘post’, ‘post_status’ =>’publish’, ‘tax_query’ => array( ‘taxonomy’ => ‘category’, ‘field’ => ‘id’, ‘terms’ => array( 10, 11, 57 ), ‘operator’ => ‘NOT IN’, ) ); Or shorter: $args = array( ‘numberposts’ => ’10’, ‘post_type’ => ‘post’, ‘post_status’ … Read more

Empty excerpt using wp_get_recent_posts

The post_excerpt value is empty because you have no explicit excerpts for your posts. While the_excerpt() does generate an excerpt from the posts content if the post excerpt is empty, the function wp_get_recent_posts(), which is basically a wrapper for get_posts(), doesn’t.

How to target the default Recent Posts and Recent Comments widgets with pre_get_posts?

pre_get_posts is executed before each and every query. Your $query->is_main_query() is making this code change the query only for the Main query. So, if you’re in an archive page, you’re modifying only the archive posts, and not any of the others queries (widgets, menus, etc). But be aware, that code you added there will change … Read more

Show one post per author and limit query to 8 posts

I believe that you can achieve this effect by grouping the query by author ID, which will require a filter(mostly cribbed from the Codex): function my_posts_groupby($groupby) { global $wpdb; $groupby = “{$wpdb->posts}.post_author”; return $groupby; } add_filter( ‘posts_groupby’, ‘my_posts_groupby’ ); If you have less than 8 authors, however, this won’t work. (You will get a number … Read more