- This topic is empty.
-
AuthorPosts
-
April 23, 2014 at 3:01 pm #168529
mikes02
ParticipantI am working on a medical site right now where Physicians need to be grouped by locations they work at and also the department they are in, i.e. Cardiology. I have a linked screenshot here: http://ignition-labs.com/doctor-profile.jpg
As you can see, on each Physicians profile we need the ability to show the location they belong to as well as other Physicians that belong to that same practice group.
I was thinking of having two custom post types, one for Locations and one for Physicians. However, I am having a hard time figuring out what logic to use to say that if a Physician is a cardiologist, show the other cardiologists at the bottom of the page.
Hopefully I explained that clearly. Just looking for some assistance with the logic to use.
Thank you.
April 23, 2014 at 4:15 pm #168532Alen
ParticipantI wouldn’t create two separate custom post types, I would create taxonomy for each distinction. So post type would be Physicians, and two taxonomies would be Location and Department.
April 23, 2014 at 4:19 pm #168533Alen
ParticipantApril 23, 2014 at 4:22 pm #168534mikes02
ParticipantThank you for that. So on the page itself how would I find what taxonomy the current physician belongs to and only show other doctors belonging to that taxonomy?
April 23, 2014 at 4:22 pm #168535Alen
ParticipantThis will be helpful as well: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
April 23, 2014 at 4:30 pm #168538mikes02
ParticipantRight, but then wouldn’t I need a unique query for every single department/location combination? Isn’t there a way to determine what department they belong to dynamically and query based on that information?
For example, if I am looking at a Cardiologist’s profile, only other Cardiologists should be displayed, Dermatologists wouldn’t be part of that group, if that makes sense.
April 23, 2014 at 5:24 pm #168541mikes02
Participant<?php // FIND PHYSICIANS BASED ON THEIR TAXONOMY AND DISPLAY THEM HERE // GET THE ASSIGNED TAXONOMY ON THE CURRENT POST $post_terms = wp_get_object_terms($post->ID, 'department', array('fields'=>'ids')); // GET THE ID OF THE CURRENT POST SO WE CAN EXCLUDE IT FROM RESULTS $currentID = get_the_ID(); // QUERY BASED ON CURRENT TAXONOMY $args = array( 'post_type' => 'physician', 'post__not_in' => array($currentID), 'tax_query' => array( array( 'taxonomy' => 'department', 'field' => 'id', 'terms' => $post_terms ) ) ); $the_query = new WP_Query($args); ?> <h3>Cardiology Physicians</h3> <?php // LOOP THROUGH PHYSICIANS THAT SHARE THE SAME TAXONOMY if($the_query->have_posts()): while($the_query->have_posts()): $the_query->the_post(); ?> <div class="profile-item"> <div class="name"> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><strong><?php the_title(); ?></strong> <?php echo get_field('title'); ?></a> </div> <div class="thumb"> <?php $image = wp_get_attachment_image_src(get_field('image'), 'physician-thumb'); ?> <img src="<?php echo $image[0]; ?>" alt=""> </div> </div> <?php endwhile; endif; wp_reset_postdata(); ?>
April 23, 2014 at 10:16 pm #168552mikes02
ParticipantThe above seems to be working for me, however, is it possible to do it if a Physician were assigned to multiple departments and not just one department? So that way they showed up in both places?
This may never happen, since it’s such a specialized field, but for example what if a Physician needed to be in Dermatology and Cardiology, is it possible to adjust the query so that he/she would show up in both places?
-
AuthorPosts
- The forum ‘Other’ is closed to new topics and replies.