1

I need to list out a custom post type organised by two different taxonomies on these posts.

I have a custom post type of properties with taxonomies of location and size and am trying to list them out like the below

Example

I can only seem to get them to sort by one category and cant seem to get the second layer introduced im using this code how do I get this to sorting by size as well like the image above

          <?php
      $_terms = get_terms( array('property_location') );

      // $_terms = get_terms( array('apartment_type') );
      foreach ($_terms as $term) :
          $term_slug = $term->slug;
          $_posts = new WP_Query( array(
                      'post_type'         => 'property',
                      'posts_per_page'    => 20, //important for a PHP memory limit warning
                      'tax_query' => array(
                          array(
                              'taxonomy' => 'property_location',
                              'field'    => 'slug',
                              'terms'    => $term_slug,
                          ),
                      ),
                  ));
          if( $_posts->have_posts() ) : ?>
            <div class="property">
            <?php echo '<h3>'. $term->name .'</h3><hr />';

              while ( $_posts->have_posts() ) : $_posts->the_post();

                $title = get_field('title');
                $navtitle = get_field('navigation_title');
                $content = get_field('content');
                $terms = get_the_terms( $post->ID, 'property_type' );
                $location = get_the_terms( $post->ID, 'property_location' );

              ?>
                      <a href='#<?php echo $navtitle; ?>'>
                        <?php the_title(); ?>
                      </a>
              <?php
            endwhile; ?>
          </div>
          <?php endif;
          wp_reset_postdata();

      endforeach;
      ?>

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.