Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between get_terms and get_the_terms in WordPress ?

Tags:

wordpress

I need your help.

My question is what is the difference between get_terms and get_the_terms in WordPress ?

I know that get_the_terms for example give me set of categories that a post attached to them, but really I can't understand what get_terms do and how it different from get_the_terms ?

thank you all.

like image 582
Mohamad Haidar Avatar asked Jul 24 '14 04:07

Mohamad Haidar


People also ask

What is Get_terms?

The 'get_terms' filter will be called when the cache has the term and will pass the found term along with the array of $taxonomies and array of $args. This filter is also called before the array of terms is passed and will pass the array of terms, along with the $taxonomies and $args.

How do I find the current post taxonomy in WordPress?

You can use get_the_terms() .

How do I get the terms for a custom post type in WordPress?

<? php $terms = wp_get_post_terms( $query->post->ID, array( 'country', 'subject' ) ); ?> <? php foreach ( $terms as $term ) : ?>


1 Answers

In the WordPress Codex you can find:

For get_the_terms: "Retrieve the terms of the taxonomy that are attached to the post." http://codex.wordpress.org/Function_Reference/get_the_terms

For get_terms: "Retrieve the terms in a taxonomy or list of taxonomies." http://codex.wordpress.org/Function_Reference/get_terms

So, as you said, get_the_terms() will get the terms (e.g. categories) attached to a post, whereas get_terms() will retrieve the terms in a taxonomy (e.g. categories in the category taxonomy). For example, get_terms( 'category' ) will return all categories that you have added to your WordPress site.

like image 136
Ap Koponen Avatar answered Sep 28 '22 04:09

Ap Koponen