• Hi everyone,

    before creating this new topic I’ve been looking around to hopefully find an answer to my question, but it didn’t quite work out.

    Here is my problem:
    I’ve got a custom post type called “property” with the following custom taxonomies:
    1) “offertype”, (hierarchical), which takes only two terms (sell, rent);
    2) “propertycat” (hierarchical), which contains 3 terms (business, residencial, investments)
    3) “propertytype” (non hierarchical), which contains terms such as condo, apartment, single family home, etc.
    4) “location”, (non hierarchical), which takes location names like Boston, Chicago, New York, ect.

    If I query something like https://www.mysite.com/?offertype=sell&propertycat=residential I get an archive of posts for all residential properties available for sell.
    On the same archive page I would like to display in a separate dropdown menu only for those terms from the taxonomy “propertytype”, which the currently displayed posts belong to.

    I’m not a developer so I’ve trying my best to understand how to find a decent solution:

    inside my taxonomy.php I’ve tried to declare a custom loop just to create my list of taxonomy terms and test my archive example:

    I’m using

    $customloop = new WP_Query(offertype=sell&propertycat=residential);

    and after calling the loop like this

    <?php if ($customloop->have_posts()) : while($customloop->have_posts()) : $customloop->the_post(); ?>

    I create my list of terms by using

    $property_types = wp_get_object_terms($post->ID, 'propertytype');
    if(!empty($property_types)){
      if(!is_wp_error( $property_types )){
        foreach($property_types as $term){
          echo '<option value="term->slug">'.$term->name.'</option>';
        }
      }
    }

    Here comes my pain: inside my dropdowm menu I get all the terms from the taxomony “propertytype” associated with every single post. In other words, some of the terms get duplicated if two properties are both saved as “apartment” and that’s not what I’m expecting. I would like to get a clean list of taxonomy terms, which can be found inside my archive page.

    Any help would be appreciated. Thanks in advance!

  • The topic ‘Taxonomy terms list based on displayed posts’ is closed to new replies.