• Resolved brogr

    (@brogr)


    hi,

    the plugin description sounds exactly like what I’m looking for, but unfortunately it doesn’t seem to work in my case. based on two separate taxonomies I’m trying to get posts of a custom post_type.

    my url:
    ?post_type=project&projectprogram=program1&projectstatus=status1
    also tried with query_posts:

    query_posts( array(
      'post_type' => 'project',
      'projectprogram' => 'program1',
      'projectstatus' => 'status1'
    ) );

    in both cases the behaviour / filtering of the plugin doesn’t work correctly. it falsely also returns posts associated with only one of the taxonomies. it behaves as if the WHERE clause would be WHERE projectprogram='program1' OR projectstatus='status1', but I’m looking for something that does WHERE projectprogram='program1' AND projectstatus='status1'.

    i’m using the more taxonomies plugin to register the custom taxonomies, but i’ve exported the code in order to set public to 1. this is the code i’m now using to register them:

    add_filter('more_taxonomies_saved', 'more_taxonomies_saved_projectprogram');
    function more_taxonomies_saved_projectprogram ($d) {$d['projectprogram'] = maybe_unserialize('a:15:{s:12:"hierarchical";s:1:"1";s:6:"public";s:1:"1";s:5:"label";s:0:"";s:14:"singular_label";s:0:"";s:4:"name";s:0:"";s:7:"show_ui";s:1:"1";s:7:"rewrite";s:1:"1";s:12:"rewrite_base";s:14:"projectprogram";s:13:"show_tagcloud";s:1:"0";s:14:"query_var_bool";s:1:"1";s:9:"query_var";s:14:"projectprogram";s:5:"index";s:15:"projectprogram";s:12:"ancestor_key";s:0:"";s:11:"object_type";a:1:{i:0;s:7:"project";}s:6:"labels";a:14:{s:4:"name";s:16:"projectprograms";s:13:"singular_name";s:15:"projectprogram";s:12:"search_items";s:6:"Search";s:13:"popular_items";s:7:"Popular";s:9:"all_items";s:3:"All";s:11:"parent_item";s:6:"Parent";s:17:"parent_item_colon";s:6:"Parent";s:9:"edit_item";s:4:"Edit";s:11:"update_item";s:6:"Update";s:12:"add_new_item";s:7:"Add New";s:13:"new_item_name";s:8:"New Name";s:26:"separate_items_with_commas";s:20:"Separate with commas";s:19:"add_or_remove_items";s:13:"Add or Remove";s:21:"choose_from_most_used";s:34:"Choose from the most commonly used";}}', true); return $d; }
    add_filter('more_taxonomies_saved', 'more_taxonomies_saved_projectstatus');
    function more_taxonomies_saved_projectstatus ($d) {$d['projectstatus'] = maybe_unserialize('a:15:{s:12:"hierarchical";s:1:"1";s:6:"public";s:1:"1";s:5:"label";s:0:"";s:14:"singular_label";s:0:"";s:4:"name";s:0:"";s:7:"show_ui";s:1:"1";s:7:"rewrite";s:1:"1";s:12:"rewrite_base";s:13:"projectstatus";s:13:"show_tagcloud";s:1:"0";s:14:"query_var_bool";s:1:"1";s:9:"query_var";s:13:"projectstatus";s:5:"index";s:13:"projectstatus";s:12:"ancestor_key";s:0:"";s:11:"object_type";a:1:{i:0;s:7:"project";}s:6:"labels";a:14:{s:4:"name";s:13:"projectstatus";s:13:"singular_name";s:13:"projectstatus";s:12:"search_items";s:13:"Search status";s:13:"popular_items";s:14:"Popular status";s:9:"all_items";s:10:"All status";s:11:"parent_item";s:13:"Parent status";s:17:"parent_item_colon";s:13:"Parent status";s:9:"edit_item";s:11:"Edit status";s:11:"update_item";s:13:"Update status";s:12:"add_new_item";s:14:"Add new status";s:13:"new_item_name";s:15:"New status name";s:26:"separate_items_with_commas";s:27:"Separate status with commas";s:19:"add_or_remove_items";s:20:"Add or remove status";s:21:"choose_from_most_used";s:41:"Choose from the most commonly used status";}}', true); return $d; }

    Any clue what’s going wrong here?

    Thanks and best,
    Brogr

Viewing 14 replies - 1 through 14 (of 14 total)
  • Thread Starter brogr

    (@brogr)

    I’ve now tested it with taxonomies created with register_taxonomy. Same results, unfortunately. The code I’ve used:

    //hook into the init action and call create_taxonomies when it fires
    add_action( 'init', 'create_taxonomies', 0 );
    
    //create two taxonomies, genres and writers for the post type "book"
    function create_taxonomies()
    {
      // Add new taxonomy, make it hierarchical (like categories)
      $labels = array(
        'name' => _x( 'projectprograms', 'taxonomy general name' ),
        'singular_name' => _x( 'projectprogram', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search projectprograms' ),
        'all_items' => __( 'All projectprograms' ),
        'parent_item' => __( 'Parent projectprogram' ),
        'parent_item_colon' => __( 'Parent projectprogram:' ),
        'edit_item' => __( 'Edit projectprogram' ),
        'update_item' => __( 'Update projectprogram' ),
        'add_new_item' => __( 'Add New projectprogram' ),
        'new_item_name' => __( 'New projectprogram Name' ),
      );
      register_taxonomy('projectprograms', array('project'), array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'projectprograms' ),
      ));
    
      // Add new taxonomy, NOT hierarchical (like tags)
      $labels = array(
        'name' => _x( 'projectstatus', 'taxonomy general name' ),
        'singular_name' => _x( 'projectstatus', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search projectstatus' ),
        'popular_items' => __( 'Popular projectstatus' ),
        'all_items' => __( 'All projectstatus' ),
        'parent_item' => __( 'Parent projectstatus' ),
        'parent_item_colon' => __( 'Parent projectstatus:' ),
        'edit_item' => __( 'Edit projectstatus' ),
        'update_item' => __( 'Update projectstatus' ),
        'add_new_item' => __( 'Add New projectstatus' ),
        'new_item_name' => __( 'New projectstatus Name' ),
        'separate_items_with_commas' => __( 'Separate projectstatus with commas' ),
        'add_or_remove_items' => __( 'Add or remove projectstatus' ),
        'choose_from_most_used' => __( 'Choose from the most used projectstatus' )
      ); 
    
      register_taxonomy('projectstatus', array('project'), array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'projectstatus' ),
      ));
    }
    Plugin Author scribu

    (@scribu)

    Here’s some debugging code (just place it in your theme’s functions.php file):

    function qmt_debug( $wp_query ) {
      echo '<pre>';
      print_r( $wp_query );
      echo '</pre>';
    }
    add_action('loop_start', 'qmt_debug');

    Let me know what you get.

    Thread Starter brogr

    (@brogr)

    without query_posts() in template file:

    WP_Query Object
    (
        [query_vars] => Array
            (
                [post_type] => projekt
                [projectstatus] => gebaut
                [taxonomy] => projectstatus
                [term] => gebaut
                [error] =>
                [m] => 0
                [p] => 0
                [post_parent] =>
                [subpost] =>
                [subpost_id] =>
                [attachment] =>
                [attachment_id] => 0
                [name] =>
                [static] =>
                [pagename] =>
                [page_id] => 0
                [second] =>
                [minute] =>
                [hour] =>
                [day] => 0
                [monthnum] => 0
                [year] => 0
                [w] => 0
                [category_name] =>
                [tag] =>
                [cat] =>
                [tag_id] => 0
                [author_name] =>
                [feed] =>
                [tb] =>
                [paged] => 0
                [comments_popup] =>
                [meta_key] =>
                [meta_value] =>
                [preview] =>
                [s] =>
                [sentence] =>
                [category__in] => Array
                    (
                    )
    
                [category__not_in] => Array
                    (
                    )
    
                [category__and] => Array
                    (
                    )
    
                [post__in] => Array
                    (
                    )
    
                [post__not_in] => Array
                    (
                    )
    
                [tag__in] => Array
                    (
                    )
    
                [tag__not_in] => Array
                    (
                    )
    
                [tag__and] => Array
                    (
                    )
    
                [tag_slug__in] => Array
                    (
                    )
    
                [tag_slug__and] => Array
                    (
                    )
    
                [posts_per_archive_page] => 25
                [caller_get_posts] =>
                [suppress_filters] =>
                [cache_results] => 1
                [update_post_term_cache] => 1
                [update_post_meta_cache] => 1
                [posts_per_page] => 25
                [nopaging] =>
                [comments_per_page] => 50
                [no_found_rows] =>
                [order] => DESC
                [orderby] => wp_posts.post_date DESC
            )
    
        [request] =>  SELECT SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts  WHERE 1=1  AND wp_posts.ID IN (104)  AND wp_posts.post_type = 'projekt' AND (wp_posts.post_status = 'publish')  ORDER BY wp_posts.post_date DESC LIMIT 0, 25
        [post_count] => 1
        [current_post] => -1
        [in_the_loop] => 1
        [post] => stdClass Object
            (
                [ID] => 104
                [post_author] => 1
                [post_date] => 2010-08-18 21:57:01
                [post_date_gmt] => 2010-08-19 01:57:01
                [post_content] => Ersatzneubau für die Kehrichtverwertungsanlage Bern (KVA) im Rahmen des neu erschlossenen Infrastrukturstandorts Bern Forsthaus West / Die Anlage produziert Fernw?rme und Strom mittels dreier Linien: Kehrichtverbrennung, Holzheizkraftwerk, Gas- und Dampfkombikraftwerk / ?hnlich einem Container- frachtschiff im Hafen, liegt der Neubau der KVA am Stadtrand von Bern - zwischen der Hauptstrasse Richtung Murten und der Westtangente der A1, in einem Restwaldstück des Grossen Bremgartenwalds / Um zukünftigen Anpassungen der Verfah- rentechnik gerecht werden zu k?nnen, muss die Konstruktions- weise des Geb?udes best?ndig aber flexibel sein / Der Geb?u- desockel und der Kehrichtbunker sind deshalb aus Ortbeton, die Hallen der Verfahrenstechnik als tektonische Hülle aus vorge- fertigten Betonelementen konstruiert / Ein 300m langer Besu- cher- und Besichtigungsgang zieht sich entlang des gesamten Geb?udes / Durch gezielte Einblicke in den Verfahrensprozess und seine grosszügige ?ffnung gegen den umliegenden Wald, schafft er einen Bezug zwischen der ?Maschine“ auf der einen und der Natur auf der anderen Seite.
                [post_title] => Neue Kehrichtverwertungsanlage Forsthaus Bern
                [post_excerpt] =>
                [post_status] => publish
                [comment_status] => closed
                [ping_status] => closed
                [post_password] =>
                [post_name] => neue-kehrichtverwertungsanlage-forsthaus-bern
                [to_ping] =>
                [pinged] =>
                [post_modified] => 2010-09-23 15:42:51
                [post_modified_gmt] => 2010-09-23 19:42:51
                [post_content_filtered] =>
                [post_parent] => 0
                [guid] => https://localhost/wordpress3/?post_type=projekt&p=104
                [menu_order] => 0
                [post_type] => projekt
                [post_mime_type] =>
                [comment_count] => 0
                [filter] => raw
            )
    
        [comments] =>
        [comment_count] => 0
        [current_comment] => -1
        [comment] =>
        [found_posts] => 1
        [max_num_pages] => 1
        [max_num_comment_pages] => 0
        [is_single] =>
        [is_preview] =>
        [is_page] =>
        [is_archive] => 1
        [is_date] =>
        [is_year] =>
        [is_month] =>
        [is_day] =>
        [is_time] =>
        [is_author] =>
        [is_category] =>
        [is_tag] =>
        [is_tax] => 1
        [is_search] =>
        [is_feed] =>
        [is_comment_feed] =>
        [is_trackback] =>
        [is_home] =>
        [is_404] =>
        [is_comments_popup] =>
        [is_admin] =>
        [is_attachment] =>
        [is_singular] =>
        [is_robots] =>
        [is_posts_page] =>
        [is_paged] =>
        [query] => Array
            (
                [post_type] => projekt
                [projectstatus] => gebaut
                [taxonomy] => projectstatus
                [term] => gebaut
            )
    
        [posts] => Array
            (
                [0] => stdClass Object
                    (
                        [ID] => 104
                        [post_author] => 1
                        [post_date] => 2010-08-18 21:57:01
                        [post_date_gmt] => 2010-08-19 01:57:01
                        [post_content] => Ersatzneubau für die Kehrichtverwertungsanlage Bern (KVA) im Rahmen des neu erschlossenen Infrastrukturstandorts Bern Forsthaus West / Die Anlage produziert Fernw?rme und Strom mittels dreier Linien: Kehrichtverbrennung, Holzheizkraftwerk, Gas- und Dampfkombikraftwerk / ?hnlich einem Container- frachtschiff im Hafen, liegt der Neubau der KVA am Stadtrand von Bern - zwischen der Hauptstrasse Richtung Murten und der Westtangente der A1, in einem Restwaldstück des Grossen Bremgartenwalds / Um zukünftigen Anpassungen der Verfah- rentechnik gerecht werden zu k?nnen, muss die Konstruktions- weise des Geb?udes best?ndig aber flexibel sein / Der Geb?u- desockel und der Kehrichtbunker sind deshalb aus Ortbeton, die Hallen der Verfahrenstechnik als tektonische Hülle aus vorge- fertigten Betonelementen konstruiert / Ein 300m langer Besu- cher- und Besichtigungsgang zieht sich entlang des gesamten Geb?udes / Durch gezielte Einblicke in den Verfahrensprozess und seine grosszügige ?ffnung gegen den umliegenden Wald, schafft er einen Bezug zwischen der ?Maschine“ auf der einen und der Natur auf der anderen Seite.
                        [post_title] => Neue Kehrichtverwertungsanlage Forsthaus Bern
                        [post_excerpt] =>
                        [post_status] => publish
                        [comment_status] => closed
                        [ping_status] => closed
                        [post_password] =>
                        [post_name] => neue-kehrichtverwertungsanlage-forsthaus-bern
                        [to_ping] =>
                        [pinged] =>
                        [post_modified] => 2010-09-23 15:42:51
                        [post_modified_gmt] => 2010-09-23 19:42:51
                        [post_content_filtered] =>
                        [post_parent] => 0
                        [guid] => https://localhost/wordpress3/?post_type=projekt&p=104
                        [menu_order] => 0
                        [post_type] => projekt
                        [post_mime_type] =>
                        [comment_count] => 0
                        [filter] => raw
                    )
    
            )
    
        [queried_object] => stdClass Object
            (
                [term_id] => 3
                [name] => Gebaut
                [slug] => gebaut
                [term_group] => 0
                [term_taxonomy_id] => 35
                [taxonomy] => projectstatus
                [description] =>
                [parent] => 0
                [count] => 1
            )
    
        [queried_object_id] => 3
    )

    with query_posts() in template file:

    WP_Query Object
    (
        [query_vars] => Array
            (
                [post_type] => projekt
                [projectprograms] =>
                [projectstatus] => gebaut
                [error] =>
                [m] => 0
                [p] => 0
                [post_parent] =>
                [subpost] =>
                [subpost_id] =>
                [attachment] =>
                [attachment_id] => 0
                [name] =>
                [static] =>
                [pagename] =>
                [page_id] => 0
                [second] =>
                [minute] =>
                [hour] =>
                [day] => 0
                [monthnum] => 0
                [year] => 0
                [w] => 0
                [category_name] =>
                [tag] =>
                [cat] =>
                [tag_id] => 0
                [author_name] =>
                [feed] =>
                [tb] =>
                [paged] => 0
                [comments_popup] =>
                [meta_key] =>
                [meta_value] =>
                [preview] =>
                [s] =>
                [sentence] =>
                [category__in] => Array
                    (
                    )
    
                [category__not_in] => Array
                    (
                    )
    
                [category__and] => Array
                    (
                    )
    
                [post__in] => Array
                    (
                    )
    
                [post__not_in] => Array
                    (
                    )
    
                [tag__in] => Array
                    (
                    )
    
                [tag__not_in] => Array
                    (
                    )
    
                [tag__and] => Array
                    (
                    )
    
                [tag_slug__in] => Array
                    (
                    )
    
                [tag_slug__and] => Array
                    (
                    )
    
                [taxonomy] => projectstatus
                [term] => gebaut
                [caller_get_posts] =>
                [suppress_filters] =>
                [cache_results] => 1
                [update_post_term_cache] => 1
                [update_post_meta_cache] => 1
                [posts_per_page] => 10
                [nopaging] =>
                [comments_per_page] => 50
                [no_found_rows] =>
                [order] => DESC
                [orderby] => wp_posts.post_date DESC
            )
    
        [request] =>  SELECT SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts  WHERE 1=1  AND wp_posts.ID IN (104)  AND wp_posts.post_type = 'projekt' AND (wp_posts.post_status = 'publish')  ORDER BY wp_posts.post_date DESC LIMIT 0, 10
        [post_count] => 1
        [current_post] => -1
        [in_the_loop] => 1
        [post] => stdClass Object
            (
                [ID] => 104
                [post_author] => 1
                [post_date] => 2010-08-18 21:57:01
                [post_date_gmt] => 2010-08-19 01:57:01
                [post_content] => Ersatzneubau für die Kehrichtverwertungsanlage Bern (KVA) im Rahmen des neu erschlossenen Infrastrukturstandorts Bern Forsthaus West / Die Anlage produziert Fernw?rme und Strom mittels dreier Linien: Kehrichtverbrennung, Holzheizkraftwerk, Gas- und Dampfkombikraftwerk / ?hnlich einem Container- frachtschiff im Hafen, liegt der Neubau der KVA am Stadtrand von Bern - zwischen der Hauptstrasse Richtung Murten und der Westtangente der A1, in einem Restwaldstück des Grossen Bremgartenwalds / Um zukünftigen Anpassungen der Verfah- rentechnik gerecht werden zu k?nnen, muss die Konstruktions- weise des Geb?udes best?ndig aber flexibel sein / Der Geb?u- desockel und der Kehrichtbunker sind deshalb aus Ortbeton, die Hallen der Verfahrenstechnik als tektonische Hülle aus vorge- fertigten Betonelementen konstruiert / Ein 300m langer Besu- cher- und Besichtigungsgang zieht sich entlang des gesamten Geb?udes / Durch gezielte Einblicke in den Verfahrensprozess und seine grosszügige ?ffnung gegen den umliegenden Wald, schafft er einen Bezug zwischen der ?Maschine“ auf der einen und der Natur auf der anderen Seite.
                [post_title] => Neue Kehrichtverwertungsanlage Forsthaus Bern
                [post_excerpt] =>
                [post_status] => publish
                [comment_status] => closed
                [ping_status] => closed
                [post_password] =>
                [post_name] => neue-kehrichtverwertungsanlage-forsthaus-bern
                [to_ping] =>
                [pinged] =>
                [post_modified] => 2010-09-23 15:42:51
                [post_modified_gmt] => 2010-09-23 19:42:51
                [post_content_filtered] =>
                [post_parent] => 0
                [guid] => https://localhost/wordpress3/?post_type=projekt&p=104
                [menu_order] => 0
                [post_type] => projekt
                [post_mime_type] =>
                [comment_count] => 0
                [filter] => raw
            )
    
        [comments] =>
        [comment_count] => 0
        [current_comment] => -1
        [comment] =>
        [found_posts] => 1
        [max_num_pages] => 1
        [max_num_comment_pages] => 0
        [is_single] =>
        [is_preview] =>
        [is_page] =>
        [is_archive] => 1
        [is_date] =>
        [is_year] =>
        [is_month] =>
        [is_day] =>
        [is_time] =>
        [is_author] =>
        [is_category] =>
        [is_tag] =>
        [is_tax] => 1
        [is_search] =>
        [is_feed] =>
        [is_comment_feed] =>
        [is_trackback] =>
        [is_home] =>
        [is_404] =>
        [is_comments_popup] =>
        [is_admin] =>
        [is_attachment] =>
        [is_singular] =>
        [is_robots] =>
        [is_posts_page] =>
        [is_paged] =>
        [query] => Array
            (
                [post_type] => projekt
                [projectprograms] =>
                [projectstatus] => gebaut
            )
    
        [posts] => Array
            (
                [0] => stdClass Object
                    (
                        [ID] => 104
                        [post_author] => 1
                        [post_date] => 2010-08-18 21:57:01
                        [post_date_gmt] => 2010-08-19 01:57:01
                        [post_content] => Ersatzneubau für die Kehrichtverwertungsanlage Bern (KVA) im Rahmen des neu erschlossenen Infrastrukturstandorts Bern Forsthaus West / Die Anlage produziert Fernw?rme und Strom mittels dreier Linien: Kehrichtverbrennung, Holzheizkraftwerk, Gas- und Dampfkombikraftwerk / ?hnlich einem Container- frachtschiff im Hafen, liegt der Neubau der KVA am Stadtrand von Bern - zwischen der Hauptstrasse Richtung Murten und der Westtangente der A1, in einem Restwaldstück des Grossen Bremgartenwalds / Um zukünftigen Anpassungen der Verfah- rentechnik gerecht werden zu k?nnen, muss die Konstruktions- weise des Geb?udes best?ndig aber flexibel sein / Der Geb?u- desockel und der Kehrichtbunker sind deshalb aus Ortbeton, die Hallen der Verfahrenstechnik als tektonische Hülle aus vorge- fertigten Betonelementen konstruiert / Ein 300m langer Besu- cher- und Besichtigungsgang zieht sich entlang des gesamten Geb?udes / Durch gezielte Einblicke in den Verfahrensprozess und seine grosszügige ?ffnung gegen den umliegenden Wald, schafft er einen Bezug zwischen der ?Maschine“ auf der einen und der Natur auf der anderen Seite.
                        [post_title] => Neue Kehrichtverwertungsanlage Forsthaus Bern
                        [post_excerpt] =>
                        [post_status] => publish
                        [comment_status] => closed
                        [ping_status] => closed
                        [post_password] =>
                        [post_name] => neue-kehrichtverwertungsanlage-forsthaus-bern
                        [to_ping] =>
                        [pinged] =>
                        [post_modified] => 2010-09-23 15:42:51
                        [post_modified_gmt] => 2010-09-23 19:42:51
                        [post_content_filtered] =>
                        [post_parent] => 0
                        [guid] => https://localhost/wordpress3/?post_type=projekt&p=104
                        [menu_order] => 0
                        [post_type] => projekt
                        [post_mime_type] =>
                        [comment_count] => 0
                        [filter] => raw
                    )
    
            )
    
    )
    Plugin Author scribu

    (@scribu)

    That’s strange. In the first case, ‘projectprograms’ doesn’t even appear, while in the second one, it’s blank.

    Do the custom taxonomies show up in the Drill-Down widget?

    Thread Starter brogr

    (@brogr)

    I know… That at least kind of confirms the OR instead of AND behavior.
    Yes, both of them do appear in the widget. Any other clue? I’m using carrington, any chance it could have to do anything with that? Don’t think so, since it still uses wp functions.
    Best

    Plugin Author scribu

    (@scribu)

    No, I don’t think Carrington is the cause.

    Anyway, these kinds of queries will be native to WP 3.1 (see #12891), so I would like to concentrate my attention on that.

    It would be great if you could test this on a nightly build of WordPress and let me know how it goes. You can use the Beta Tester plugin.

    If so, remember to uninstall QMT, or upgrade it to the development version, which is compatible with WP 3.1-alpha.

    I’m having the exact same issue. I tried the plugin which did not work, and after reading this thread I just downloaded the beta plugin and a nightly build which also does not work. The last parameter just totally overwrites the first one.

    Ex: edit.php?post_type=casestudy&industry=banking&platform=twitter

    That query returns a result set that is all of the case studies where the platform is twitter, and not the platform of twitter AND industry of banking.

    Any updates on when this might be working in one of the nightly builds or the plugin?

    Plugin Author scribu

    (@scribu)

    @lsparks: so you’re using WP 3.1-alpha with QMT 1.4-alpha and it doesn’t work?

    How are you registering your taxonomies?

    Ah, just realized I was using WP 3.01 beta and not the “bleeding edge” WP 3.1 alpha. It does indeed work with the alpha versions of WP and QMT. Looks like WP 3.1 alpha is pretty unstable. I’m really excited for 3.1 to be wrapped up, I have quite a few projects that really need to be able to use multiple taxonomy queries in a stable release of WP.

    Scribu, thanks for all your contributions to the WP platform! I am relatively new to WP, and I continue to be amazed by community and the platform.

    You might want to update the plug-in page to reflect the current behavior—I just spent about an hour trying to figure out why QMT seemed to be adding taxonomy results as opposed to filtering out results. Then I found this thread.

    Unfortunately, my current project is scheduled to go live next week so I can’t move to 3.1 right now. Instead, I’ve got a workaround inside the loop, which is a bit more complicated than my original multi-taxonomy query.

    If anybody wants to do a similar workaround, here’s one approach. Note I haven’t tested it in the pasted format but it should give you the general idea.:

    <?php
    $listbody = '';
    $product_line = "bumper-stickers";
    $selected_location = 'portland';
    
    $query_args = array(
      'post_type'         =>  $content_type,
      'posts_per_page'    =>  -1, // GET ALL POSTS, USE THE POST LIMIT INSIDE THE LOOP
      'taxo_product_line'  =>  $product_line,
      // 'taxo_locations'     =>  $selected_location // THIS WILL WORK IN WORDPRESS 3.1
    );
    
    $myloop = new WP_Query($query_args);
    static $displaycount = 0; // USING A COUNTER OUTSIDE THE LOOP TO CHECK IF NO POSTS WERE RETURNED
    if ( $myloop->have_posts() )
        {
            while ( $myloop->have_posts() ) : $myloop->the_post();
            static $post_count = 0;
            $post_limit = 10;
            if ($post_count == $post_limit) //
            {
                break;
            }
            // CUSTOM FILTERING FOR THE LOCATION TAXONOMY. THIS WILL BE MOVED TO WP_QUERY IN WORDPRESS 3.1
            $postlocation_objects = get_the_terms(get_the_ID(),'taxo_locations');
            $postlocations = array();
            foreach ($postlocation_objects as $term)
            {
              $slug = $term->slug;
              $postlocations[] = $slug;
            }
            if (in_array($selected_location, $postlocations))
            {
              // WE HAVE POSTS FOR THIS LOCATION
              $listbody .= get_the_content();
              $count++;
              $displaycount++;
            }
          endwhile;
          if ($displaycount == 0) $listbody .= 'No posts for you!'; // WORKAROUND TO CHECK IF NO CONTENT WAS RETURNED FOR THIS LOCATION
        }
    else
      //  We don't have any content for this region
      {
        $listbody .= 'No posts for you!'
      }
    
    echo $listbody
    ?>

    Never mind my workaround. After investigating further, I discovered that one of my taxonomies was registered with ‘public’ => false. This was preventing multiple-taxonomy queries from working correctly, though single-taxonomy queries on the private taxonomy were working just fine.

    I’m trying to do something like this, but within the same custom taxonomy. In example:

    $args = array(
       'post_type' => 'my-post-type',
       'my-custom-taxonomy' => 'custom-term-1',
       'my-custom-taxonomy' => 'custom-term-2',
       'post-status' => 'publish'
       );
    $wp_query = new WP_Query($args);

    It works like an OR, and like @brogr says, I need something to make it work as an AND. Are you saying that we’re going to be able to perform all these kind of queries in WP 3.1?

    Plugin Author scribu

    (@scribu)

    It works like an OR, and like @brogr says, I need something to make it work as an AND.

    To perform an AND within the same taxonomy, just write:

    $args = array(
       'post_type' => 'my-post-type',
       'my-custom-taxonomy' => 'custom-term-1+custom-term-2',
       'post-status' => 'publish'
       );
    $wp_query = new WP_Query($args);

    Are you saying that we’re going to be able to perform all these kind of queries in WP 3.1?

    Yep: https://ottopress.com/2010/wordpress-3-1-advanced-taxonomy-queries/

    scribu, that code works just fine. Thanks for the tip ??

    It didn’t do the job in my case because I also need a “not in” clause (i.e. custom-taxonomy=term1+term2 AND NOT custom taxonomy=term3+term4), but of course that isn’t a plugin issue. For now I worked around the problem by building a custom SQL query, I guess I’ll have to wait for 3.1 in order to apply a proper solution.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘[Plugin: Query Multiple Taxonomies] incorrect results (seems like using OR instead of AND)’ is closed to new replies.