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.

Share Improve this question asked Jun 27, 2017 at 13:15 YaronYaron 2551 silver badge6 bronze badges 3
  • 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
Add a comment  | 

1 Answer 1

Reset to default 0

I 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