[Resolved] Get custom taxonomy terms to be displayed in relative categories?
Sorry it was really hard to think of a good topic title that would describe what I am going for. So here is the story…
I have set up a taxonomy filter for my client that displays results on the search template. Here is the main part of the code that relates to this question:
<!-- Search Results Container --> <div id="search-container"> <?php /* Start the Loop */ ?> <?php if( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php // Retrieve Custom Taxonomy Values for Each Attorney. I.e. their location, position, etc. //$location = wp_get_object_terms( $post->ID, 'locations'); //$bar_admissions = wp_get_object_terms( $post->ID, 'bar-admissions'); <-- UNCOMMENT THESE IF YOU WOULD LIKE TO INTEGRATE THEM INTO THE SEARCH RESULTS. YOU WILL ALSO HAVE TO EDIT THE SINGLE ATTORNEY SECTION AS SEEN BELOW //$languages = wp_get_object_terms( $post->ID, 'languages'); //$practice_areas = wp_get_object_terms( $post->ID, 'practice-areas'); //$schools = wp_get_object_terms( $post->ID, 'schools'); $link = get_permalink(); $position = wp_get_object_terms( $post->ID, 'positions'); $position = $position->name; $phone = get_field( 'phone_number' ); $email = get_field( 'email' ); $vcard = get_field( 'vcard' ); ?> <!-- Single Attorney Entry --> <div id="attorney-entry"> <span><a href="<?php echo $link; ?>"><strong><?php the_title(); ?></strong></a></span> <span>P: <?php echo $phone; ?></span> <span>E: <a href="mailto:<?php echo $email; ?>"><?php echo $email; ?></a></span> <span><a href="<?php echo $vcard; ?>" download><img src="<?php echo site_url( '/wp-content/themes/rodenolaw/images/vcard_download.png' ); ?>" width="48" height="48" alt="vCard"></a><span> <span class="position"><?php echo $position; ?></span> </div> <!-- /end single attorney entry --> <?php endwhile; else: ?> <!-- Message if no attorneys are found --> <p>Sorry, no attorneys matched your criteria. Please go back to our <a href="our-attorneys">attorney directory</a> and try again.</p> <?php endif; ?> </div> <!-- /end search results container -->
So I have this configured to display the results in alphabetical order according to custom taxonomy called last-name. Everything is working fine up to this point.
So what my client would like is for the the results page to look something like this: http://www.brunini.com/attorneys-search.html. As you can see, the results are organized and displayed in seperate categories according to the first letter of their last name.
What I already have set up is a custom taxonomy called last-name-latter. What I am looking to do is have the search results page check to see which terms for last-name-letter are showing up from the queried posts (the terms would be A, B, C etc.), then display alphabetical headings for the terms used as well as list the attorneys with the same terms underneath their corresponding headings. It would be easier to understand if you just visit the example site I mentioned.
I am thinking I will have to set up individual divs for every single letter, then use a conditional to display them only if their term shows up in one or more of the queried post. I will have to think through this more, but just seeing if any of you can come up with a clean solution to this.
Thanks ahead of time.
- The topic ‘[Resolved] Get custom taxonomy terms to be displayed in relative categories?’ is closed to new replies.