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.
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.
You can use get_the_terms() .
<? php $terms = wp_get_post_terms( $query->post->ID, array( 'country', 'subject' ) ); ?> <? php foreach ( $terms as $term ) : ?>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With