WordPress.org

Ready to get started?Download WordPress

Forums

WordPress the same Taxonomy and Advanced Custom Field value (1 post)

  1. ProbablyBest
    Member
    Posted 3 months ago #

    I have created a custom section within wordpress called Staff members. Within a post in this section I have created a custom taxonomy named 'Team' which the admin will tick, then using a plugin it filters depending on what has been ticked (similar to how you filter by categories in a blog section).

    Within the same Staff Members post I have an advanced custom fields taxonomy. I would like to do an if else statement that if the 2 taxonomies are ticked the same if will display something different to normal.

    Here is my custom taxonmy in my functions.php

    /* Add ROLE taxonomies to filter the staff members */
    add_action( 'init', 'create_role_taxonomy', 0);
    function create_Role_taxonomy()
    {
    register_taxonomy ( 'Role', 'profile', array( 'hierarchical' =>
    true, 'label' => 'Role', 'query_var' => true, 'rewrite' => true )
    );
    }

    Here is my frontend im trying to do an if else statement on, but not sure how to compare the values to see if they are the same as each other.

    <?php
                $acf_tax = get_field('key_person');
                $custom_tax = get_taxonomy( $taxonomy );
                if($acf_tax == $custom_tax) {
            ?>
                <div class="dotted-line">
                    <?php while(has_sub_field('staff_details')): ?>
                        <a href='<?php echo get_permalink($post->ID); ?>'><img src="<?php the_sub_field('image'); ?>"></a>
                        <h2 class="staffname">
                            <a href='<?php echo get_permalink($post->ID); ?>'><?php echo get_post_meta($post->ID,'staff_name',true); ?></a>
                        </h2>
                        <h2 class="staffrole">
                            <?php echo get_post_meta($post->ID,'staff_role',true); ?>
                        </h2>
                        <h2 class="staffnumber">
                            <?php the_sub_field('telephone_number'); ?>
                        </h2>
                        <h2 class="staffemail">
                            <?php the_sub_field('email_address'); ?>
                        </h2>
                    <?php endwhile; ?>
                </div>
            <?php else: ?>
                <?php while(has_sub_field('staff_details')): ?>
                    <a href='<?php echo get_permalink($post->ID); ?>'><img src="<?php the_sub_field('image'); ?>"></a>
                    <h2 class="staffname">
                        <a href='<?php echo get_permalink($post->ID); ?>'><?php echo get_post_meta($post->ID,'staff_name',true); ?></a>
                    </h2>
                    <h2 class="staffrole">
                        <?php echo get_post_meta($post->ID,'staff_role',true); ?>
                    </h2>
                    <h2 class="staffnumber">
                        <?php the_sub_field('telephone_number'); ?>
                    </h2>
                    <h2 class="staffemail">
                        <?php the_sub_field('email_address'); ?>
                    </h2>
                <?php endwhile; ?>
            <?php endif; ?>

Reply

You must log in to post.

About this Topic