what is the difference between get_terms and get_the_terms in WordPress ?

自作多情 提交于 2019-12-05 03:30:07

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.

In a more practical understanding, you can use get_terms outside of the loop, whilst you can only use get_the_terms inside of the loop.

In get_the_terms you can fetch terms by a particular post_id, but in get_terms you can get set of values for set of post_id (ie, post) .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!