Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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>
<?php
$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>
<?php
$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>
<?php
$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

2 Answers 2

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 at 5:29
1  
@Pieter have edited. thanks –  shahpranaf May 9 at 5:37

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 -

http://stackoverflow.com/questions/13956593/unable-to-make-isotope-filter-sort-posts-in-wp

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

Your Answer

 
discard

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.