Home > Net >  Wordpress - Display category on single page
Wordpress - Display category on single page

Time:10-11

I create a custom post type with ACF. I have two different taxonomy for this custom type :

  • Project type
  • House type

In House type, i have 4 different category :

  • all types
  • House
  • Appartement
  • Building

Each post need 'all type' and one other (for example : all type, house)

i would like to display the main category : House and not display : all types How can i hide 'all types' ?

My code :

  <div class="detailfiche">
                                <?php 
                                    global $post;
                                    $terms = wp_get_post_terms($post->ID, 'housetype');
                                    if ($terms) {
                                        $output = array();
                                        foreach ($terms as $term) {
                                            $output[] = '<span><a href="' .get_term_link( $term->slug, 'housetype') .'">' .$term->name .'</a></span>';
                                        }
                                        echo join( ' ', $output );
                                    };
                                    ?>
                            </div>

CodePudding user response:

Try this

<?php
global $post;
$terms = wp_get_post_terms($post->ID, 'housetype');
if ($terms)
{
    $output = array();
    foreach ($terms as $term)
    {
        if ($term->term_id != 222)
        {
            $output[] = '<span><a href="' . get_term_link($term->slug, 'housetype') . '">' . $term->name . '</a></span>';
        }

    }
    echo join(' ', $output);
};
?>

Change 222 in this line to your taxonomy id for exclude

$term->term_id != 222

  • Related