Support » Fixing WordPress » Can you query multiple taxonomy’s in one call?

  • Chris Olbekson

    (@c3mdigital)


    Level 12 Bug Squasher & Forum Moderator

    I am trying to list custom posts by taxonomy with the taxonomy title then the posts underneath. It works fine but I have to make a new query for each taxonomy. It seems that there must be a way to include them all in one query. Here is the code I am using:

    <?php wp_reset_query(); ?>
    <?php query_posts( array( 'classification' => 'whiskey', ) ); ?>
    <?php if( is_tax() ) {
        global $wp_query;
        $term = $wp_query->get_queried_object();
        $title = $term->name;
    }  ?></p>
    <p><ul class="shelf-talkers">
    <span class="tax-title"><?php echo($title); ?></span>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?></p>
    
    <li><a class="zoom" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
    <?php endwhile; else: ?>
    <?php endif; ?>
    </ul>

    This query is repeated around 20 times on my template. Any ideas on how to make one query that will give the same results?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Not quite sure, but this article by Justin Tadlock may have what you want.

    Sorry, I just now realized that what I posted is not going to help.

    Let me start by saying that I do not have experience with WP 3.0, but I am a little confused by your question because AFAIK, taxonomies do not have values. Are you talking about Custom Fields? Can you post the request that results from the example you showed? That might help to clarify.

    Chris Olbekson

    (@c3mdigital)

    Level 12 Bug Squasher & Forum Moderator

    You can view the result of the above query on this page: http://globalqualityimports.com/classification/whiskey/
    This works fine and gives me the results I want. On this page:
    http://globalqualityimports.com/products/
    The above query is repeated for each taxonomy and I would like to simplify it or combine it into one query that produces the same results. After much research I don’t think it is possible.

    Sorry, I guess I wasn’t quite clear. What I wanted to see was the output of print_r($wp_query->request); done just after the query_posts so I could look at the SQL generated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Can you query multiple taxonomy’s in one call?’ is closed to new replies.