i want to filter some custom post types with ajax or jquery.
i have 4 pages with some custom fields:
1 – blue / green
2 – red /green / black
3 – yellow / black
4 – yellow
on the page (frontend) i need to filter it this way (select-boxes):
first all 4 pages are visible. when i click the checkbox “green” the pages 3 and 4 disappear. then i click the checkbox “blue” and page 2 disappears, too. then i click “yellow” and all pages are gone because there is no page with the custom field entrys “green + blue + yellow”.
any idea? searched the web up and down but found nothing, only scripts where page 3 + 4 were visible at least because they only check the last option …
This is what you need to do:
1. Create a select field with the options
2. Write some jQuery to trigger a function on change of this select
3. Get the JS function to do an AJAX call to a WP ajax function
4. Create this WP ajax function in your functions.php
5. Get your JS to post the selected value to the php function
6. Get your php function to use this value to filter the posts and return the correct data
7. Get your js function to use this data on complete.
You will find a tutorial in the docs on querying the posts based on a custom field value, the rest is up to you and google.
now i used this:
with custom fields. awesome 🙂