You will either need to do two things
-
Check for an empty array AND a
WP_Error
object -
Check if the taxonomy exists (which
get_categories()
andget_terms()
already does) before your execute your code and still check for an empty array
FEW NOTES TO CONSIDER
-
get_categories()
usesget_terms()
, you you could useget_terms()
-
You do not need to set arguments if you use it’s default values
-
date
is not a valid value fororderby
inget_terms()
. Valid values arename
,slug
,term_group
,term_id
,id
,description
andcount
-
The
type
parameter inget_categories()
does not relate to the post type, but to the taxonomy type. This parameter used to acceptlink
as value and where used before the introduction of custom taxonomies in WordPress 3.0. Before WordPress 3.0, you could settype
tolink
to return terms from thelink_category
taxonomy. This parameter was depreciated in WordPress 3.0 in favor of thetaxonomy
parameter
SOLUTION
//Get all EVENT categories
$categories_event = get_terms( 'catevent' );
$option_value_event = array();
// Check for empty array and WP_Error
if ( $categories_event
&& !is_wp_error( $categories_event )
) {
//Extract all EVENT categories
foreach ( $categories_event as $cat ){
$option_value_event[] = $cat->name;
}
}
EDIT
I cannot see why the above code would not work. You can try the following as a test
if ( taxonomy_exists( 'catevent' ) ) {
//Get all EVENT categories
$categories_event = get_terms( 'catevent' );
$option_value_event = array();
// Check for empty array and WP_Error
if ( $categories_event
&& !is_wp_error( $categories_event )
) {
//Extract all EVENT categories
foreach ( $categories_event as $cat ){
$option_value_event[] = $cat->name;
}
}
}
That should work, if not, then you have a serious error somewhere in one of your plugins