I'm trying to use get_posts to only return posts that have an excerpt. Done lots of searching and have been trying to use "posts_where" filter on the query but my SQL is lacking. This is what I'm using which in theory I think should work, but really I have no idea on the sql and can't work out how to print the sql string for this query to debug...
$args = array(
'post_type' => 'testimonial',
'numberposts' => 1,
'orderby' => 'rand',
);
add_filter( 'posts_where' , 'posts_where_excerpt_not_empty' );
$post = get_posts($args);
remove_filter( 'posts_where' , 'posts_where_excerpt_not_empty' );
[...]
function posts_where_excerpt_not_empty( $where ) {
$where .= " post_excerpt NOT NULL";
return $where;
}