Help working with Objects
Posted: Sun Dec 07, 2014 3:37 pm
I am working in WordPress and I am trying to get some information into a variable. I am trying to get the names of categories. So I do this
The above returns this
so then I thought that I would be able to do this
But when I do that, I get an error, "Trying to get property of non object".
What am I doing wrong?
Code: Select all
$categories = get_categories();
var_dump($categories);
Code: Select all
array(15) {
[4]=>
object(stdClass)#369 (15) {
["term_id"]=>
&string(3) "191"
["name"]=>
&string(11) "Band member"
["slug"]=>
&string(11) "band-member"
["term_group"]=>
string(1) "0"
["term_taxonomy_id"]=>
string(3) "192"
["taxonomy"]=>
string(8) "category"
["description"]=>
&string(0) ""
["parent"]=>
&string(1) "0"
["count"]=>
&string(1) "4"
["cat_ID"]=>
&string(3) "191"
["category_count"]=>
&string(1) "4"
["category_description"]=>
&string(0) ""
["cat_name"]=>
&string(11) "Band member"
["category_nicename"]=>
&string(11) "band-member"
["category_parent"]=>
&string(1) "0"
}
Code: Select all
$slug = $categories->slug;
echo $slug;
What am I doing wrong?