I have eleven categories I’ve created in WordPress with a post for each one. The categories are really destinations (as in ‘travel’). I would like a way for the site visitor to select and compare categories and have the result shown on one page.
Example: This link as it is, will show categories 7 and 8 on the same page. I would like a way to produce this result dynamically via checkboxes or something similar.
With jQuery you can use Ajax to load the categories through a PHP file which fetches them from the WordPress database. If we assume you use json as datatype, and you return a structure like this:
Where each
keyis the name of a selected category, and eachvalueis a string containing the ids of the posts included in the category (this is just an example of how the data could be returned).You can then iterate through the returned data like this:
Your function is called everytime a checkbox is changed:
Now this is not perfect, and you need to write the PHP file that fetches the categories, but hopefully it gets your going!
References: