Empty excerpt using wp_get_recent_posts

I have this simple shortcode to display the last posts with it’s title and except: add_shortcode(‘latest3’, function(){ $recent_posts = wp_get_recent_posts( array( ‘numberposts’ => 3, ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’ ), ARRAY_A); $output=”<h2>Latest posts</h2>”; foreach ( $recent_posts as $recent ) { $output .= ‘<h3>’.$recent[“post_title”].'</h3>’; $output .= $recent[“post_excerpt”]; } return … Read more

How to exclude categories from recent posts, recent comments & category widgets?

I use the bellow function (thanks to @helgatheviking!) to exclude categories from the wordpress loop. It works very well – posts of selected categories are excluded from the loop on the main blog listing page, from category listing pages and from archives, but not from Recent Posts and not from Recent Comments in sidebar. How … Read more

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

I added the following to my functions.php: add_action(‘pre_get_posts’, ‘keyl_get_emp_posts’); function keyl_get_emp_posts($query) { if ($query->is_main_query()) $query->set(‘post_type’, ’employee’); } and so far it’s effectively filtering out the search results. The default widgets Recent Posts and Recent Comments aren’t budging, though. What gives? 2 Answers 2 pre_get_posts is executed before each and every query. Your $query->is_main_query() is making … Read more