get_category
is returning null but using get term_by
or get_categories()
is not. Why?
I have created term called categorycourses. I have a post related to coursecategory Lidköping (vardump1),
vardump1
object(stdClass)[2525]
public 'term_id' => &int 5
public 'name' => &string 'Lidköping' (length=10)
public 'slug' => &string 'kurser_lidkoping' (length=16)
public 'term_group' => int 0
public 'term_taxonomy_id' => int 105
public 'taxonomy' => string 'category' (length=8)
public 'description' => &string '' (length=0)
public 'parent' => &int 0
public 'count' => &int 1
public 'filter' => string 'raw' (length=3)
public 'cat_ID' => &int 5
public 'category_count' => &int 1
public 'category_description' => &string '' (length=0)
public 'cat_name' => &string 'Lidköping' (length=10)
public 'category_nicename' => &string 'kurser_lidkoping' (length=16)
public 'category_parent' => &int 0
vardump2
null
vardump3
object(stdClass)[2525]
public 'term_id' => int 105
public 'name' => string 'Skara' (length=5)
public 'slug' => string 'kurser_skara' (length=12)
public 'term_group' => int 0
public 'term_taxonomy_id' => int 108
public 'taxonomy' => string 'categorycourses' (length=15)
public 'description' => string 'skara' (length=5)
public 'parent' => int 0
public 'count' => int 1
public 'filter' => string 'raw' (length=3)
I see that taxonomy returned by get_category
is 'category', while taxonomy returned by get_category
is 'categorycourses'.
Here's the code I'm using:
//Vardump1
$location = get_category(skovdeLocationId); //another location id
var_dump($location);
//Vardump2
$location = get_category(skaraLocationId, 'categorycourses');
var_dump($location); //returns null (with or without taxonomy defined)
//Vardump3
$location = get_term_by( 'id', skovdeLocationId, 'categorycourses' );
var_dump($location);
But
get_categories(array(
'taxonomy' =>'categorycourses',
'include' => skaraLocationId
));
is returning term correctly (as vardump1 but where location = skaraLocationId)
Why? Shouldn't get_categories and get_category be the same? (or get_termby)