functions.php 内からカスタム関数を呼び出しても機能しないのはなぜですか?
私のカスタム関数:
function get_cat_slug($ID) {
$post_id = (int) $ID;
$category = &get_category($post_id);
echo $category->slug;
}
次のように、すべての投稿をループします。
$args = array(
'numberposts' => -1
);
$posts = get_posts($args);
foreach ($posts as $post){
// and withing this lopp I would like to get a category slug
// so I am calling my custom function, also included in functions.php
get_cat_slug($post->ID);
}
しかし、get_cat_slug($post->ID)
常に戻りnull
ます。なんで?私は何が欠けていますか?どんな提案でも大歓迎です。