Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other [WordPress] Question about tagging logic

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #168529
    mikes02
    Participant

    I 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.

    #168532
    Alen
    Participant

    I 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.

    https://gist.github.com/alenabdula/11235805

    #168533
    Alen
    Participant
    #168534
    mikes02
    Participant

    Thank 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?

    #168535
    Alen
    Participant
    #168538
    mikes02
    Participant

    Right, 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.

    #168541
    mikes02
    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(); ?>  
    #168552
    mikes02
    Participant

    The 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?

Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘Other’ is closed to new topics and replies.