Filtering WP_Query Dynamically on the Front-End

Here’s what I did recently on a site, which should be easily adapted for your case. I was using jQuery for a number of things on this site, so relied on that.

While WP has some great AJAX handling, it was simpler in this instance for me to just use jQuery’s AJAX load() method. If your current page has an element div#loaded-content-area and you want to fill it with the part of another web page’s div#content-to-load then you simply need to run the jQuery:

$("div#loaded-content-area")
.load("http://www.example.org/page-of-data/ #content-to-load");

So, to solve your problem I would make sure I label the key content within my taxonomy-term template in the theme with ID="content-to-load" (or whatever ID suits you, of course).

Load the list of term permalinks in your displayed page and attach a click handler to each which passes the href attribute from the permalink as jQuery’s .load URL. Then clicking on a term will cause jQuery to fetch the content that you want from the term page and display it within the current page without a refresh.

This approach has a couple of advantages:

1 – Progressive Enhancement. If for any reason a browser doesn’t have JavaScript, then the term page will just load as normal instead.

2 – No need for clever fiddling with a query: The term pages do it all for you.