I'm trying to create a few custom post types, and instead of hard-coding their names I just want to define them as a globally scoped variable.
I thought I understood the scope but apparently not. The code below results in an error of Undefined variable
:
$filmLabel = "Films";
$showLabel = "Shows";
function CreatePostTypes() {
register_post_type( $filmLabel, GenerateFilmType($filmLabel));
register_post_type( $showLabel, GenerateFilmType($showLabel));
}
add_action( 'init', 'CreatePostTypes' );
I've tried using $GLOBAL
as well, with the same result.
Can anyone spot what's wrong?
define()
which seems a bit dated in modern PHP, I would simply go with a public class constant.