get_terms和get_the_terms区别


Updated on: June 9, 2020 in Wordpress by

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.