Solution:1
You can check for the error with is_wp_error()
,
$terms = get_terms( array(
'taxonomy'=> 'category',
'parent' => 2818,
'hide_empty' => 0)
);
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
echo '<ul>';
foreach ( $terms as $term ) {
echo '<li>' . $term->name . '</li>';
}
echo '</ul>';
}
else{
$error_string = $terms->get_error_message();
echo '<div id="message" class="error"><p>' . $error_string .'</p></div>';
}
About the error you told in comment, it’s look like you don’t run with a WordPress version under 4.5 ?
Prior to 4.5.0, the first parameter of get_terms() was a taxonomy or list of taxonomies:
$terms = get_terms( 'post_tag', array( 'hide_empty' => false, ) );
Since 4.5.0, taxonomies should be passed via the ‘taxonomy’ argument in the $args array:
$terms = get_terms( array( 'taxonomy' => 'post_tag', 'hide_empty' => false, ) );
About get_terms()
In your case, remove taxonomy
from $args and
$terms = get_terms('category', $args);