dimanche 4 octobre 2015

Wordpress query to show only posts where content is not empty

I am using a query to show only 1 custom post type randomly on my home page. I'm trying to filter out the posts where the content is empty so as to not show those posts in the loop. Is it possible to set the query to only show post that "post_content" is not empty? I've tried "meta_query" with no luck. As covered here.

I have also played around with other things, like trying to get the next post in the loop if the content is empty, but can't find a way to do that either.

Here is something I was trying to get the next post, if content is empty. But I don't think "get_next_post();" works that way.

$loop = new WP_Query( array(
        'post_type' => 'custom',
        'post_status' => 'publish', 
        'posts_per_page' => 1,
        'orderby' => 'rand',
        'order' => 'DESC',
    ) );
while ( $loop->have_posts() ) : $loop->the_post();

if($post->post_content=="") {
get_next_post();
} else {
the_title();
the_content();
};
endwhile;

Any suggestions would be appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire