I’m to dumb right now â¦
print_r($terms);
does this â¦
Array
(
[7] => stdClass Object
(
[term_id] => 7
[name] => Testwhatever
[slug] => testwhatever
[term_group] => 0
[term_taxonomy_id] => 7
[taxonomy] => event_type
[description] =>
[parent] => 0
[count] => 2
[object_id] => 8
)
)
How can I print
the slug?
I thought print print($terms->slug)
should do the job, but it says: “Trying to get property of non-object”
update:
function get_event_term($post) {
$terms = get_the_terms( (int) $post->ID, 'event_type' );
if ( !empty( $terms ) ) {
print_r($terms);
return $terms[7]->slug;
}
}
Its an array of objects (even if it contains only a single entry at index “7”), not a single object
With multiple “things
try
you object stdclass is in array[7] offset.
Or, to complicate things a little bit:
Try this.
print_r ($terms[7]->slug)
looks logical to me, since it’s an array of objectsUPDATE
Since you are unsure how many items
get_event_term
should return, you should return an Array.Function using the wp_parse_args system to manage its single $args argument, which could be given whatever values you wanted. In this case $args stores detailed display overrides, a pattern found in many WordPress functions.
works fine for me more detail
http://codex.wordpress.org/Function_Reference/wp_parse_args