I don't want to display post with empty body / post_content on my home page. So I added below code to my function.php. It detects post with empty body but it still display them. I expected that if I return '' the post won't be displayed.
- How can I remove post from displaying?
- How does the filter the_posts work?
The code:
function remove_post_with_empty_body ( $posts ) {
if (($posts->post_content) == '') {
echo 'empty'; //also tried return false; and return null;
return '';
}
else {
echo 'not empty';
return $posts;
}
}
add_action('the_post', 'remove_post_with_empty_body');