How to get wordpress empty content list

2019-09-21 12:35发布

问题:

i make two list theme

1.the posts have featured image and title, but empty content. i want get this list.

2.and other posts with content list.

I don't have any idea, help me please

回答1:

Try to use below code:

$args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'orderby' => 'ID',
    'order' => 'desc');

$blank_posts = array();

$posts = new WP_Query( $args );

if ( $posts->have_posts() ) : 
    while ( $posts->have_posts() ) : $posts->the_post();
       $content = get_the_content();
        if($content == '') { 
            array_push( $blank_posts, $post);
        }
    endwhile;
endif;

/* print all blank content posts */
//echo "<pre>"; print_r($blank_posts);

/* loop */

if(!empty($blank_posts)){
    foreach ($blank_posts as $pst) {
        echo "ID= ". $pst->ID . ', '. "Title= ". $pst->post_title .'<hr />';
    }
}


标签: wordpress