• hi
    so i am just trying to figure out a taxonomy query & what i want is when the user lands on the custom taxonomy archive page, i want to display to them all the product categories of the posts (products) for that page. so i want to find all categories & all subcategories for the posts. Custom taxonomy is workplace as below:

    so maybe its something like this:

    
    $term = get_queried_object();
    
    $args = array(
        'post_type' => 'post',
        'tax_query' => array(
            'relation' => 'AND',
            array(
                'taxonomy' => 'product_cat',
                'field'    => 'slug'
                ,
            ),
            array(
                'taxonomy' => 'workplace',
                'field'    => 'slug',
                'terms'    => $term,
                'operator' => 'IN',
            ),
        ),
    );
    $query = new WP_Query( $args );

    But i just can’t figure out how to ONLY display their categories rather than the actual posts. I had it working perfect through using the woo product loop until i realised it was affecting pagination.

    • This topic was modified 2 years, 8 months ago by mirwordpress.
    • This topic was modified 2 years, 8 months ago by mirwordpress.
    • This topic was modified 2 years, 8 months ago by mirwordpress.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter mirwordpress

    (@mirwordpress)

    More info:

    since the default behaviour of archive-product is to display posts, I want the query to still find the posts, but to extract the product categories from them & then display those to the user. I also need the query to take into account the custom taxonomy for that page.

    Moderator bcworkz

    (@bcworkz)

    You can use wp_get_object_terms() to get a product’s assigned product category terms.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp query display product categories for custom taxonomy’ is closed to new replies.