admin管理员组文章数量:1315069
I have a custom taxonomy A with some terms (A1, A2,A3, etc) and a second custom taxonomy B. I want to create a custom field in taxnomony B which will be a dropdown menu with the terms from taxonomy A. I am able to create custom fields with texts and to get the terms from taxonomy A with get_terms(). The get_terms() function, returns an array of object (every object is a term). I am not sure how to build the dropdwon. How can I connect them? (I want to do it programmatically so that I can use the code for more than one sites) Thank you
I have a custom taxonomy A with some terms (A1, A2,A3, etc) and a second custom taxonomy B. I want to create a custom field in taxnomony B which will be a dropdown menu with the terms from taxonomy A. I am able to create custom fields with texts and to get the terms from taxonomy A with get_terms(). The get_terms() function, returns an array of object (every object is a term). I am not sure how to build the dropdwon. How can I connect them? (I want to do it programmatically so that I can use the code for more than one sites) Thank you
Share Improve this question edited Nov 22, 2020 at 14:24 marissalianam asked Nov 21, 2020 at 21:43 marissalianammarissalianam 211 silver badge3 bronze badges2 Answers
Reset to default 0You can use ACF (Advanced Custom Fields) plugin to do this. Select Taxonomy field and set the field group to appear where you need to.
I'm pretty sure the free version of the plugin has this field.
Instead of showing custom field with text, create a custom field with select dropdown.
Populate that dropdown options with get_terms function (term_id as value)
Add multiple attribute to select if you need to store more than one term relation.
Store values as array of term ids
On frontend loop trough saved array and use get_term function to get term object data.
p.s. on 4) you should check if saved term id exists, if not then you should take care of it (delete the relation or ignore on loop I guess)
本文标签: Custom field with terms from another taxonomy programmatically
版权声明:本文标题:Custom field with terms from another taxonomy programmatically 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741972633a2407931.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论