WP_Query with strange multiple conditions
-
Hello my WordPress friends,
I am developing with WP since, I would say a bit more then 14 months now.
Since a couple of days, i have the awesome ToDo, to create a Portfolio with an Ajax request, and I am stuck …
Facts:
I have 3 different taxonomies:
‘taxonomy’ => ‘auftragsgrafik_slug_list’,
‘field’ => ‘slug’,
‘terms’ => $typefilter,‘taxonomy’ => ‘thema’,
‘field’ => ‘slug’,
‘terms’ => $themefilter,‘taxonomy’ => ‘auftragsgrafik_complexity’,
‘field’ => ‘slug’,
‘terms’ => $complexityfilter,I try to explain it “short”..
3 Dropdowns, each of it has a bunch of values.
Lets say:
.) Dropdown A (‘auftragsgrafik_slug_list‘)
–> TestA
–> TestB
–> TestC
.) Dropdown B (‘thema‘)
–> LunchA
–> LunchB
–> LunchC
–> LunchD
–> LunchE
–> LunchF
.) Dropdown C (‘auftragsgrafik_complexity‘)
–> CoffeeA
–> CoffeeB
–> CoffeeC
–> CoffeeD
–> CoffeeE
(u got the Idee)If now “TestA” is selected, I just want all Post results where the Taxonomy is linked with TestA.
If TestA and LunchA is selected, I want only the Post results where both “TestA AND LunchA” are linked via taxonomies to the posts!
If TestA, LunchA and CoffeeA is selected, I just want Post results where all 3 Taxonomies match with posts!I googled, tried, worked, but I found no working Solution for me :/
My actuall work looks kinda like this:
I just post the code for 1 Request here, to avoid a bit of spam!
$args = array( 'posts_per_page' => $entries, 'meta_query' => array(array('key' => '_thumbnail_id')), 'post_type' => 'auftragsgrafik_post', 'post_status' => 'publish', 'tax_query' => array( array( 'relation' => 'OR', array( 'taxonomy' => 'auftragsgrafik_slug_list', 'field' => 'slug', 'terms' => $typefilter, 'relation' => 'OR', ), array( 'taxonomy' => 'thema', 'field' => 'slug', 'terms' => $themefilter, 'relation' => 'OR', ), array( 'taxonomy' => 'auftragsgrafik_complexity', 'field' => 'slug', 'terms' => $complexityfilter, ) ), 'relation' => 'OR', array( 'taxonomy' => 'auftragsgrafik_slug_list', 'field' => 'slug', 'terms' => $typefilter, 'relation' => 'AND', array( 'taxonomy' => 'thema', 'field' => 'slug', 'terms' => $themefilter, ), ), 'relation' => 'OR', array( 'taxonomy' => 'auftragsgrafik_slug_list', 'field' => 'slug', 'terms' => $typefilter, 'relation' => 'AND', array( 'taxonomy' => 'auftragsgrafik_complexity', 'field' => 'slug', 'terms' => $complexityfilter, ), ), ), );
I definitely know that this can not work, I spend to much time now to know it… so I need some Guidance here my friends :-/
PLEASEWhat is the best way to make it work with my specific requirements?
I also tried it to make multiple “args” and merge those together, but sadly I don’t get it to work..I hope you have the Knowledge, in which I am leaking… hope you can help me ??
Nice greetings, Raphael
- The topic ‘WP_Query with strange multiple conditions’ is closed to new replies.