I try to create an array of years, which is avaible in my template-files and in at least one other function in the functions.php.
function get_the_years()
{
global $year_arr = range(2001, date('Y'));
return $year_arr;
}
Then I want to use it in a function, which creates a term for every year in the custom taxonomy 'year'.
function create_year_terms() {
foreach($year_arr as $value){
$term = term_exists($value, 'year');
if ($term !== 0 && $term !== null) {
echo $value . ' category exists!';
}
else { wp_insert_term(
$value, // the term
'year', // the taxonomy
array(
'description'=> 'The name of a year',
'slug' => $value )
);
echo'term '. $value . ' created';
}
}
}
And trying to attach this function to the wp_login hook
add_action('wp_login', 'create_year_terms');
I tried to make my hoeworks and I guess I understand "something" but I'm a bit scared to kill something by putting wrong stuff in my functions.php, so please excuse my question.