您的代码:
$content = get_the_content();
if(empty($content)) {...}
您可以将代码替换为:
if ($posts->post_content == \'\'){...}
这不是测试,只是尝试一下,我希望有用。
编辑
请尝试此代码。
$args = array(
\'post_type\' => \'post\',
\'post_status\' => array(\'publish\', \'pending\', \'draft\', \'auto-draft\', \'future\', \'private\', \'inherit\', \'trash\'),
\'posts_per_page\' => -1,
\'orderby\' => \'ID\',
\'order\' => \'desc\');
$blank_posts = array();
$content_post =array();
$posts = new WP_Query( $args );
if ( $posts->have_posts() ) :
while ( $posts->have_posts() ) : $posts->the_post();
global $post;
$content = get_the_content();
if(empty($content)) {
array_push( $blank_posts, $post);
}else{
array_push( $content_post, $post);
}
endwhile;
endif;
/* print all blank content posts */
var_dump($blank_posts);
var_dump($content_post);
if(!empty($blank_posts)){
foreach ($blank_posts as $pst) {
echo "ID= ". $pst->ID . \' : \'. "Title= ". $pst->post_title .\'<hr />\';
}
}