I need to filter posts by a custom field value.
My specific example:
- User browse to products > category 1 > subcategory A.
- ALL “subcategory A” items (products custom post type) are displayed
as default by date. - Each item in subcategory A has a custom field “size”. User can select the size with a dropdown menu and posts are filtered displaying only items with “custom field:size” = “selected size”. Filter is kept also in pagination, because products are on more pages.
I’ve checked a lot of answers, but no case was simple as that. I was thinking about doing it using a custom search or a plugin, but I really don’t know where to start. thanks for your help.
EDIT: the custom field values are fixed, not auto-populated. The select can be built in plain html without extra queries.
Edited according to first comments and Pastebin code:
See Codex for WP_Query reference.