只显示帖子选定的分类术语?
使用 wp_get_post_terms() 时,我可以生成与帖子相关的分类术语列表。但是,我只想显示为该帖子选择的分类术语。使用上述函数和 get_terms() 将成功找到分类术语,但它将显示所有术语。不仅是那些被选中的人。在函数的 $args 数组中,我寻找了“选定”过滤器,但没有找到,当我尝试它时,它不起作用。
我是否正在尝试做一些无法完成的事情?我确信这就是我眼前的东西。我只是想在对我的做事方式做出重大改变之前询问专业人士。
When using wp_get_post_terms() I can produce a list of taxonomy terms associated with a post. However, I only want to show the taxonomy terms that have been selected for that post. Using the aforementioned function and get_terms() will successfully find the taxonomy terms, but it will show all of the terms. Not only the ones that have been selected. In the $args array for the functions I've looked for a 'selected' filter, but I found none and when I tried it, it didn't work.
Am I trying to do something that can't be done? I'm sure it's something that is starring me right in the face. I just want to ask the pro's before I make major changes to the way I'm doing things.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
wp_get_post_terms
仅返回为该帖子选择的术语,不会返回所有分类术语。http://codex.wordpress.org/Function_Reference/wp_get_post_terms
wp_get_post_terms
only returns terms that have been selected for that post, it doesn't return all taxonomy terms.http://codex.wordpress.org/Function_Reference/wp_get_post_terms
这对我来说效果很好。我只是将分类法块发送到浏览器,并使用上面的代码遍历它们。
我通过这个发送:
This works well for me. I simply send the taxonomy slug to browser, and itterate through them with the code above.
I send by this:
你可以试试这个代码,它对我有用。我有一个名为“商店”的分类法,我想显示从中选择的 2 个分类法。所以我使用了包含功能。
You can try out this code, it worked for me. I have a taxonomy named 'stores' and i wanted to display 2 selected taxonomy from it. so i used a include feature.
如果你想要它而不需要术语链接,你可以使用这个
And if you want it without the term linking you can use this