简体   繁体   English

查询用户并从自定义分类中获取条款

[英]Query User and get terms from a custom Taxonomy

Wordpress newbie here stuck a little bit. WordPress的新手在这里卡住了一点。

I have created a custom taxonomy called 'Retailer Category' for Users as per http://justintadlock.com/archives/2011/10/20/custom-user-taxonomies-in-wordpress ... when adding a new user I can successfully select terms from this custom taxonomy that are then saved. 我根据http://justintadlock.com/archives/2011/10/20/custom-user-taxonomies-in-wordpress为用户创建了一个名为“零售商类别”的自定义分类法...添加新用户时,我可以从此自定义分类标准中成功选择术语,然后将其保存。

Using the tutorial above I can get all Users with a particular term however I'd actually like to get all terms from the custom Taxonomy (Retailer Category) for a logged in User ie to create a custom profile page that outputs the standard User info plus a list of the Retailer Categories the user selected. 使用上面的教程,我可以获取带有特定术语的所有用户,但是我实际上想从已登录用户的自定义分类法(零售商类别)中获取所有术语,即创建一个输出标准用户信息的自定义配置文件页面,用户选择的零售商类别列表。

Searching Google results in heaps of tutorials/code etc that mention Posts and Custom Post Types but nothing that I can see that mentions Users and a Custom Taxonomy. 在Google的搜索结果中,出现了大量教程/代码等内容,其中提到了帖子和自定义帖子类型,但我看不到提到用户和自定义分类法的内容。

Any help/pointer would be much appreciated. 任何帮助/指针将不胜感激。 Thanks. 谢谢。

You should use the get_the_terms method and supply the user id and taxonomy and it will return an array of term objects associated to the user on success. 您应该使用get_the_terms方法并提供用户ID和分类法,一旦成功,它将返回与用户相关联的术语对象数组。 False if no terms are found in the given taxonomy and a wp_error object if an invalid taxonomy is entered. 如果在给定的分类法中未找到任何术语,则为False;如果输入的分类法无效,则为wp_error对象。

$terms = get_the_terms( $user_id, $taxonomy);

documentation: http://codex.wordpress.org/Function_Reference/get_the_terms 文档: http : //codex.wordpress.org/Function_Reference/get_the_terms

When I tried get_the_terms it didn't work. 当我尝试get_the_terms时不起作用。 Looking into the code, it is specific to posts. 查看代码,它特定于帖子。 The more general wp_get_object_terms works better. 更通用的wp_get_object_terms效果更好。 http://codex.wordpress.org/Function_Reference/wp_get_object_terms http://codex.wordpress.org/Function_Reference/wp_get_object_terms

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM