Displaying Info From a Specific Custom Taxonomy Term(Hierarchical Taxonomies) On WordPress

See also Custom Taxonomy Page Example.

I’ve written before about registering and displaying custom post types on WordPress. So you’d better check my previous post to understand what is coming next(the example bellow is based on the previous post).
Eu escrevi anteriormente sobre registrar e exibir tipos de posts customizados no WordPress. Então é melhor você conferir meu post anterior, para entender o que vem por aí(o exemplo abaixo é baseado no post anterior).

As you could see, one of the cool things about WordPress custom post types is that you can register also hierarchical taxonomies that will work as “regular” post categories for your custom post types.
Como você pôde ver, uma das coisas legais nos tipos de posts customizados do WordPress, é que você pode também registrar taxonomias hierárquicas, que vão funcionar como categorias “normais” para seus tipos de posts customizados.

Although these facilities, it took me some work to find a simple way to display some info from hierarchical taxonomies(or, let’s say custom categories), and bellow(in few lines), I’ll share the result of this work with you.
Apesar destas facilidades, me custou algum trabalho descobrir um jeito simples de exibir algumas informações das taxonomias hierárquicas, e abaixo(em poucas linhas), eu vou dividir o resultado deste trabalho com vocês.

<?
// # to retrieve an array with all info from a custom term 'scifi' 
// that "begins" to a hierarquical taxonomy called 'genre'
$term = get_term_by('slug','scifi','genre');

// the example above uses slug to retrieve the info, but you can
// use other parameters, try searching for get_term_by method on WordPress Codex

// # to display 'scifi' term description defined on wp-admin
echo $term->description . "<br>";

//# you can also display the name, slug, or even the term_id
echo $term->name . "<br>";
echo $term->slug . "<br>";
echo $term->term_id . "<br>";

//# to print the array and see all the available info
print_r($term);
?>

Hope you find it useful. As I said, it looks simple and easy, but took me some work to find. 😉
Espero que você ache útil. Como eu disse, parece simples e fácil, mas me custou algum trabalho descobrir. 😉

For further info, visit the Codex.
Para mais informações, visite o Codex.

,

  1. WordPress Custom Taxonomy Page Example – Displaying Custom Post Types Posts « It works on WordPress

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: