I am a bit confused.

I've an assortment:


$terms = get_the_terms($post->ID, 'pf');

Also it results:

Array ( [15] => stdClass Object ( [term_id] => 15 [title] => Text [slug] => text [term_group] => [term_taxonomy_id] => 33 [taxonomy] => pf [description] => An PF article. [parent] => [count] => 3 [object_id] => 694 ) )

And That I want simply to output slug ("text" within this situation) rather than the entire array.

So I am doing:

<?php $terms = get_the_terms($post->ID, 'pf');
             echo $terms["slug"]; ?>

Also it results nothing.

This provides no results too:

echo "{$terms['slug']}";

Any ideas?


I can not use $term[15]->slug since my script depends on [taxonomy] (pf within this situation)! :) So you can't really do this without foreach loop?

terms array 15 index contain object access such as this

echo $term[15]->slug

there's stdclass object at index 15 from the inside arry which may be converted/utilized as array by casting but do this insted


Following on Pekka's answer, should you reformat your print_r() output, you'd get:

Array (
    [15] => stdClass Object (
        [term_id] => 15
        [name] => Text
        [slug] => text
        [term_group] => 0
        [term_taxonomy_id] => 33
        [taxonomy] => pf
        [description] => An PF article.
        [parent] => 0
        [count] => 3
        [object_id] => 694

When dumping out a flexible with print_r(), it is good practice to surround the phone call with <pre> tags - print_r does not inflict HTML-ification from the data, therefore the nice indentation it will with arrays will get lost when seen within an HTML page. While using <pre> tags preserves the formatting. using var_dump() is going to do exactly the same, but additionally add type/size data towards the dump output.