tax_query problem with update 4.1
-
Hello, Rachel. The following code works fine upto wordpress 4.0, but it doesn’t work on 4.1.
$args = array( 'post_type' => 'brand', 'posts_per_page' => '-1', 'tax_query' => array( array( 'taxonomy' => 'catalogue', 'field' => 'id', 'terms' => $post_id, ), ) ); $loop2 = new WP_Query( $args );
The following code works fine too on 4.1:
$args = array( 'post_type' => 'brand', 'posts_per_page' => '-1', 'tax_query' => array( ) ); $loop2 = new WP_Query( $args );
Thank you
-
I’m about to push out an update that hopefully takes care of the problem.
Thank you. On another topic, you suggested that decision:
// Get the taxonomy $taxonomy = isset( $this_query[ 'taxonomy' ] ) ? $this_query[ 'taxonomy' ] : NULL; // Make sure the taxonomy exists if ( ! $taxonomy || ! taxonomy_exists( $taxonomy ) ) continue;
But it did not help me
Let’s move back to that thread. Now that I’ve pushed out the update, I’m gonna close this one up.
If anyone else has this issue after upgrading to version 1.3.2, please let me know.
Thanks!
Problem resolved.
Thanks!Awesome! Thanks for letting me know!
Rachel, I have another problem. I’m not 100 % sure that the case in the plugin, and not in my code, but the situation is as follows:
This code works fine:
$args = array( 'post_type' => 'goods', 'posts_per_page' => '-1', 'tax_query' => array( array( 'taxonomy' => 'brand', 'field' => 'id', 'terms' => $brand_id, ) ) ); $loop2 = new WP_Query( $args );
and this is fine too:
$args = array( 'post_type' => 'goods', 'posts_per_page' => '-1', 'tax_query' => array( array( 'taxonomy' => 'catalogue', 'field' => 'id', 'terms' => $catalogue_id, ) ) ); $loop2 = new WP_Query( $args );
But when I collect terms together, I can not get a list of products:
$args = array( 'post_type' => 'goods', 'posts_per_page' => '-1', 'tax_query' => array( array( 'taxonomy' => 'brand', 'field' => 'id', 'terms' => $brand_id, ), array( 'taxonomy' => 'catalogue', 'field' => 'id', 'terms' => $catalogue_id, ) ) ); $loop2 = new WP_Query( $args );
Well, by default when you do multiple tax queries, the relationship is set to “and”. Do you have any products that are that specific brand AND that specific catalogue?
If you want to show products that are that specific brand OR that specific catalogue, then make the following tweak:
$args = array( 'post_type' => 'goods', 'posts_per_page' => '-1', 'tax_query' => array( 'relation' => 'OR', array( 'taxonomy' => 'brand', 'field' => 'id', 'terms' => $brand_id, ), array( 'taxonomy' => 'catalogue', 'field' => 'id', 'terms' => $catalogue_id, ) ) ); $loop2 = new WP_Query( $args );
Неllo!
So, I found a script that shows that the error not in WordPress update, but in plugin update to version 1.3.21) I restored from a backup the old code and database. So I turned WordPress 4.0 plugin 1.3.1
2) This code worked fine:
$args = array( 'post_type' => 'goods', 'posts_per_page' => '-1', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'brand', 'field' => 'id', 'terms' => $brand_id, ), array( 'taxonomy' => 'catalogue', 'field' => 'id', 'terms' => $catalogue_id, ) ) ); $loop2 = new WP_Query( $args );
3) I just updated the plugin to version 1.3.2 and the goods are no longer displayed
4) But this code not worked too:
$args = array( 'post_type' => 'brand', 'posts_per_page' => '-1', 'tax_query' => array( array( 'taxonomy' => 'catalogue', 'field' => 'id', 'terms' => $post_id, ), ) ); $loop2 = new WP_Query( $args );
5) I just updated WordPress to version 4.1, and code specified in paragraph 4 earned. Сode specified in paragraph 2 not earned.
Ok. I think I found, and fixed, the issue. I’m gonna wait another day or two to push out an update to see if any other bugs are found.
In the meantime, the fix is in the plugin’s trunk folder so to get the fix go to the plugin’s developers page and download the “Development Version”.
I just changed to the development version and am still having an issue. I have this query:
new \WP_Query(array( 'post_type' => 'post', 'post_status' => 'publish', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'issue', 'field' => 'id', 'terms' => get_the_ID() ), array( 'taxonomy' => 'post_tag', 'field' => 'id', 'terms' => array( 108 ), 'operator' => 'NOT IN' ) ), 'posts_per_page' => -1 ));
This is the query being returned:
SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta AS cpt_onomy_pm1 ON (wp_posts.ID = cpt_onomy_pm1.post_id AND cpt_onomy_pm1.meta_key = '_custom_post_type_onomies_relationship') WHERE 1=1 AND 0 = 1 AND wp_posts.post_type = 'post' AND ((wp_posts.post_status = 'publish')) AND ( cpt_onomy_pm1.meta_value IN (65652) AND wp_posts.ID NOT IN ( SELECT object_id FROM wp_term_relationships WHERE term_taxonomy_id IN (108) ) ) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC
There is a 0 = 1 that is breaking the query. I will attempt to see why this is not being removed later today and let you know what line is failing.
Ok. I forgot about, and forgot to test, ‘NOT IN’ relationships.
Update to the development version one more time and it should be fixed. I’m working on a couple other small fixes so I should be pushing out another update in the next day or 2.
Thanks for working with me!
I upgraded to the development version and the issue is not fixed. There is still a 0 = 1 in the query.
Hmm. Odd. I wonder if it’s because it’s a CPT-onomy tax query mixed in with a taxonomy tax query. I didn’t think about that. Let me run a few tests on my end and see if I can recreate it.
Ok. Try the development version again.
That worked 🙂
- The topic ‘tax_query problem with update 4.1’ is closed to new replies.