Conditional output if post body is empty

There is a bug in views related to conditional output based on post content so this is a work around.

In themes functions file:

// Views test for post content
add_shortcode ( 'wpv-post-getcontent', 'wpv_getcontent' );
function wpv_getcontent() {
global $post;
if(get_the_content() != '') :
return 1;
else :
return 0;
endif;
wp_reset_query();
}

Then in view template:

[wpv-if evaluate="'[wpv-post-getcontent]' = '1'"]Conditional output here[/wpv-if]

Original post here:

https://wp-types.com/forums/topic/testing-for-empty-post-body/

Leave a Comment