wp_list_categories() by multiple custom taxonomy queries
-
I have two custom taxonomies, one for “client,” which is literally the client’s name, so “John Smith,” and another for “clothing,” which is like “pants, shirts, shoes.”
The “client” tax is used to attach content to a client, and is used for images and other cpt. The “clothing” tax is only attached to images and used to sort images based on their category.
I’m trying to show a list of categories that is custom to each client, meaning, if a single client only has 2 images attached to clothing – > shirt, when this client is logged in looking at their account page on the front-end of the site, I only want that client to see a single tax term from clothing for “shirts.”
By default, wp_list_categories() would return all categories site-wide, including every client and every image of every client. That is not what I want.
This code returns what I want, but it’s not unique to the client:
wp_list_categories( array( 'orderby' => 'title', 'order' => 'ASC', 'show_count' => true, 'title_li' => '', 'taxonomy' => 'clothing', ));
I’m trying to add an additinal tax query to the above to make the output unique to a specific client, from the client tax.
This returns the same as the above:
wp_list_categories( array( 'orderby' => 'title', 'order' => 'ASC', 'show_count' => true, 'title_li' => '', 'taxonomy' => 'clothing', 'tax_query' => array( array( 'taxonomy' => 'client', 'field' => 'slug', 'terms' => $currentUser, ), ), ));
Note: $currentUser outputs the correct logged in test user in all these examples
Last, I tried this but it still returns all of the “clothing” tax items.
wp_list_categories( array( 'orderby' => 'title', 'order' => 'ASC', 'show_count' => true, 'title_li' => '', 'taxonomy' => 'clothing', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'clothing', 'field' => 'slug', 'terms' => array(), ), array( 'taxonomy' => 'client', 'field' => 'slug', 'terms' => $currentUser, ), ), ) );
So my relation => ‘AND’ is not filtering properly. For the clothing tax query, I want it to return all terms that are attached, for the client tax query, I want to then limit the clothing terms returned to only belonging to that client.
What am I missing with this, provided it’s even possible?
- The topic ‘wp_list_categories() by multiple custom taxonomy queries’ is closed to new replies.