WordPress.org

Ready to get started?Download WordPress

Forums

Query Multiple Taxonomies
[resolved] Error if empty results when querying multiple taxonomies (16 posts)

  1. chymera00
    Member
    Posted 3 years ago #

    When making a query of multiple taxonomies, the results come up fine if there's a match found. However if no match is found, the query prints out ALL of my posts. Am I doing something wrong here?

    I'm using wordpress 3.0.1 and query multiple taxonomies 1.3alpha
    (also used 1.2 with same results)

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

    $args=array(
    'destinations' => 'palawan',
    'classification' => 'attractions',
    'paged' => $paged,;

    query_posts($args);

    if ( have_posts() ) : while ( have_posts() ) : the_post();

    query_loop_list(); ?>
    <?php endwhile; ?>
    <center><?php wp_pagenavi(); ?></center>

    <?php else: ?>
    <?php endif; ?>

    <?php wp_reset_query(); ?>

  2. colosimo
    Member
    Posted 3 years ago #

    same issue here, wp 3.0.1 and query multiple taxonomies 1.2
    here is my code (works fine when matches, shows everything when not)

    <?php query_posts("partner=bill&brand=ford"); ?>
    <?php while (have_posts()) : the_post(); ?>
    <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>
  3. charlieperrins
    Member
    Posted 3 years ago #

    Hi

    I'm having a similar problem but instead of getting all my posts shown the plugin is generating a 404 error.

    WordPress: Version 3.0.1.
    Plugin: Version 1.2.3

    Line 76 in 'core.php' appears to be generating this 404 result:

    if ( empty( self::$post_ids ) )
    			return $wp_query->set_404();

    Rather than generating a 404 error I want the page to reload with an empty post set so I can use the standard loop and have_posts() function to generate my page content:

    <?php if (have_posts()) : ?>
    			<!-- do something with posts -->
    		<?php else : ?>
    			<!-- show 'no posts' message -->
    		<?php endif; ?>

    Anybody have any ideas?

  4. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    This should be fixed in the latest development version (1.3-alpha2).

  5. colosimo
    Member
    Posted 3 years ago #

    hi scribu,
    it's fixed but there is a new issue:

    if i query multiple terms for one taxonomy, it shows again ALL my posts, from every tag and category.
    <?php query_posts("cat=5&partner="bill,robert,john");?>

    if i query one term works fine:
    <?php query_posts("cat=5&partner="bill");?>

    if i query multiple taxonomies and multiple terms works fine again!
    <?php query_posts("cat=1&brand=ford&partner=bill,robert,john");?>

  6. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    Yeah, besides that, the 'cat' parameter was ignored. Both bugs are now fixed. Please re-download the development version (1.3-alpha4).

  7. colosimo
    Member
    Posted 3 years ago #

    thank you scribu!
    but i found a new bug...

    if i query just one term i get posts for all partners
    <?php query_posts("cat=5&partner="bill");?>

    i found a workaround adding a fake partner in the query
    <?php query_posts("cat=5&partner="bill,fakepartner");?>
    but it's a bit hacky.

    thank you for your work, i'm definitely going to donate. =)

  8. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    A better workaround would be to use category_name instead:

    <?php query_posts("category_name=your-category-slug&partner="bill");?>

  9. chymera00
    Member
    Posted 3 years ago #

    thanks for the reply scribu. Much appreciated!

  10. chymera00
    Member
    Posted 3 years ago #

    Found a problem with development version (1.3-alpha4). I'm using the multiple taxonomy queries in my taxonomy.php
    The taxonomy templates display fine during the past versions but it's all messed up now.

    Just for more info my taxonomy.php is built around

    <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>

    then using $term->slug and $term->name for the queries

  11. chymera00
    Member
    Posted 3 years ago #

    Found out that my taxonomy.php is being bypassed and it goes directly to archive.php for the template.

  12. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    Just for more info my taxonomy.php is built around

    <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>

    A better way to do it is:

    $term = $wp_query->get_queried_object();

    Of course, that won't work when you're querying multiple terms, like ?color=green,yellow or ?color=green&shape=round.

    I usually create a multitax.php file and then replace everything in taxonomy.php with this:

    include_once './multitax.php';

  13. fussco
    Member
    Posted 3 years ago #

    scribu -- Thanks a million for the plugin.
    1.3 alpha 4 WP 3.0.1

    With the plugin deactivated the following works like a charm:

    $args = array(
    'post_type' => 'restaurants',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'order' => 'ASC',
    'orderby' => 'title'
    );
    query_posts($args);

    When the plugin is activated the above returns nothing.

    I tested and if I don't query a taxonomy for a custom post type it displays nothing, yet if I create a dud custom taxonomy called "things" with term "thing" and assign it to each of my posts the following works like a charm:

    $args = array(
    'post_type' => 'restaurants',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'order' => 'ASC',
    'orderby' => 'title',
    'things' => 'thing'
    );
    query_posts($args);

    Can the next update include a fix for this? I'm under a crazy deadline, so please let me know if this is an easy/fast fix and when you think it might be available.

    Thanks again 100000000000 :)

  14. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    1.3-alpha5 will be available in about 15 minutes after I write this.

  15. fussco
    Member
    Posted 3 years ago #

    That fixed it. Much appreciated scribu. YOU RULE!

  16. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    I usually create a multitax.php file and then replace everything in taxonomy.php with this:

    include_once './multitax.php';

    That is no longer necessary. All queries are now directed to taxonomy.php:

    development version (1.3-alpha6).

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic