Hi, I am using this function to check for an empty container of a post body:
function wpv_conditional_post_has_content($type, $object) {
$return = 0;
if ( $type == 'posts' ) {
if ( empty( $object->post_content ) ) {
$return = 0;
} else {
$return = count($object->post_content);
}
}
return $return;
}
I got from this article: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-custom-functions-in-conditions/
When I updated my php version to 7.3. I started to get a php error:
"Warning: count(): Parameter must be an array or an object that implements Countable in ... "
I need your help to fix this function so it would work for PHP 7.3
Link to a page where the issue can be seen:
versteckter Link
Hi there,
Thank you for contacting us and I'll be happy to assist.
That code is shown on the guide as an example and for PHP 7.3+, you can update your code to:
function wpv_conditional_post_has_content($type, $object) {
$return = 0;
if ( $type == 'posts' ) {
if ( empty( $object->post_content ) ) {
// return 0 when post's content is empty
$return = 0;
} else {
// return 1 when post's content is not empty
$return = 1;
}
}
return $return;
}
After that, you'll be able to use this function in conditional blocks as:
[wpv-conditional if="( wpv_conditional_post_has_content() eq '0' )"]
This post has no content
[/wpv-conditional]
[wpv-conditional if="( wpv_conditional_post_has_content() eq '1' )"]
This post has some content
[/wpv-conditional]
I hope this helps and please let me know how this goes.
regards,
Waqar
My issue is resolved now. Thank you!