1

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 Jun 27 '17 at 13:25
  • 1
    I'd suggest using a taxonomy instead of a custom field. Querying by a custom field tends to perform poorly. – WebElaine Jun 27 '17 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 Jun 28 '17 at 5:51
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.