WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using get_terms I've created three lists of term links. What currently happens if I click on a term is to see the archive for that term, what I'm attempting to achieve now is when I click a second term I want to see an archive for both terms not just the latest term. Basically creating some level of filtering posts.

My first guess is that I have to set some variable to affect the query, any suggestions on how to go about this? Or is there a better way of achieving this?

<h2>Filter By Deployment:</h2>
$deployments = get_terms( 'deployments', array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 1) );
    echo '<ul>';
    foreach ( $deployments as $deployment ) {
        echo '<li><a href="'.get_term_link($deployment->slug, 'deployments').'">'.$deployment->name.'</a></li>';
    echo '</ul>';

<h2>Filter By Category:</h2>
$categories = get_terms( 'category', array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 1) );
    echo '<ul>';
    foreach ( $categories as $category ) {
        echo '<li><a href="'.get_term_link($category->slug, 'category').'">'.$category->name.'</a></li>';
    echo '</ul>';

<h2>Filter By Keyword:</h2>
$tags = get_terms( 'post_tag', array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 1) );
    echo '<ul>';
    foreach ( $tags as $tag ) {
        echo '<li><a href="'.get_term_link($tag->slug, 'post_tag').'">'.$tag->name.'</a></li>';
    echo '</ul>';
share|improve this question
If you click now you will go to the tag archive. You can't be on 2 tag archives at once. So the filtering will have have to go to a custom page, possibly with $_GET params – janw Dec 18 '12 at 15:07
My thought to deal with that was to delete the tag.php & category.php archives so that all would default to archive.php – Chuck Dec 18 '12 at 15:15
That does trigger that behavious but that doesn't fix how you send over your params – janw Dec 18 '12 at 15:36
I did exactly this is a recent project. What I did is use a custom page and set the filter params in the url then use $_GET to rerun the query based on those filters. I'll post an answer later if no one else has posted a similar answer. – Cai Feb 12 at 8:09

Have you tried out isotope? I am working on a project that needs a similar function. So far it's the closest I've found that will sort/filter posts.

The link - http://isotope.metafizzy.co/

Here's some questions I had about implementing it with wordpress, and was able to do so to certain extent. It can help get you started -


Isotope Drop Down Categories Filter Function

share|improve this answer
That looks like something I'll have to try, I've been moved off that project until the new year, but I'll be sure to come back and let you know how it worked. Thanks – Chuck Dec 23 '12 at 14:33

Just try your condition like below.
I think $query->is_post_type_archive() will not be working properly. I have not tried that so not sure. Directly call is_post_type_archive() and is_page() function.

if ( ( is_post_type_archive( 'question' ) || is_page(3001) ) && $query->is_main_query() ) {
        $query->set( 'post_type', 'question' );

share|improve this answer
Don't just dump code as an answer. Please explain what your code does and why it should work. Please edit your answer – Pieter Goosen May 9 '14 at 5:29
@Pieter have edited. thanks – shahpranaf May 9 '14 at 5:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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