admin管理员组文章数量:1122832
I have custom post type of an animal type. (I.E I created an animals collection).
I want to give the user a drop down to select the gender and filter the displayed custom post types entries accordingly.
Right now the gender is a custom field but I can change that if there is a better approach.
I already managed to display my collection by creating an archive-animal.php.
How can I do that? I know to code but new to WordPress.
I have custom post type of an animal type. (I.E I created an animals collection).
I want to give the user a drop down to select the gender and filter the displayed custom post types entries accordingly.
Right now the gender is a custom field but I can change that if there is a better approach.
I already managed to display my collection by creating an archive-animal.php.
How can I do that? I know to code but new to WordPress.
- Well, show us the code you've tried. – CodeMascot Commented Jun 27, 2017 at 13:25
- 2 I'd suggest using a taxonomy instead of a custom field. Querying by a custom field tends to perform poorly. – WebElaine Commented Jun 27, 2017 at 14:15
- Assume I use taxonomy, What are the main guidelines about drop down controls for filtering? Is there any built-in mechanism to display them and filter by them or should I tailor it on my own? – Yaron Commented Jun 28, 2017 at 5:51
1 Answer
Reset to default 0I found the solution in this article: https://www.advancedcustomfields.com/resources/creating-wp-archive-custom-field-filter/ . I know that it causes a page refresh but going for Ajax based solution is an overkill. This solution code is very elegant and easy to follow and understand. Although taxonomy might be faster they require a lot of work with creating metaboxes and stuff so for small custom post type (Very few entries) there won't be a performance penalty.
本文标签: Filter custom post types by a field value
版权声明:本文标题:Filter custom post types by a field value 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736294229a1929311.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论