Output the post taxonomy values in Wordpress

Viewed 37

First of all I should say that I’m a beginner, I want to apologize for all the mistakes and my ignorance in coding.

I’m trying to create a custom taxonomy and assign a value for each post, I’d like to output all the values of the taxonomy and mark the assigned one. The result should be something like this

level

This is the code that I’ve tried to use

if (has_term( 'A1', 'levels' )) {
echo '<div class="level"><p class="level-title">level</p><p><mark>'?> <?php the_terms( $post->ID, 'levels'); echo '</mark> A2 B1 B2 C1 C2</p></div>';
                    }else{echo "";}
                    if (has_term( 'A2', 'levels' )) {
                        echo '<div class="level"><p class="level-title">level</p><p>A1 <mark>'?> <?php the_terms( $post->ID, 'levels'); echo '</mark> B1 B2 C1 C2</p></div>';
                    }else{echo "";}
                    if (has_term( 'B1', 'levels' )) {
                        echo '<div class="level"><p class="level-title">level</p><p>A1 A2 <mark>'?> <?php the_terms( $post->ID, 'levels'); echo '</mark> B2 C1 C2</p></div>';
                    }else{echo "";}
                    if (has_term( 'B2', 'levels' )) {
                        echo '<div class="level"><p class="level-title">level</p><p>A1 A2 B1 <mark>'?> <?php the_terms( $post->ID, 'levels'); echo '</mark> C1 C2</p></div>';
                    }else{echo "";}
                    if (has_term( 'C1', 'levels' )) {
                        echo '<div class="level"><p class="level-title">level</p><p>A1 A2 B1 B2 <mark>'?> <?php the_terms( $post->ID, 'levels'); echo '</mark> C2</p></div>';
                    }else{echo "";}
                    if (has_term( 'C2', 'levels' )) {
                        echo '<div class="level"><p class="level-title">level</p><p>A1 A2 B1 B2 C1 <mark>'?> <?php the_terms( $post->ID, 'levels'); echo '</mark></p></div>';
                    }else{echo "";}

but it seems is not working appropriately, it returns the following messages:

Notice: Undefined variable: level in /home/customer/www/englishwithfrancesca.com/public_html/wp-content/themes/storefront-child/home-template.php on line 169

Notice: Trying to get property 'slug' of non-object in /home/customer/www/englishwithfrancesca.com/public_html/wp-content/themes/storefront-child/home-template.php on line 169

I bet there’s a smarter way to code it.

Thanks in advance for any help!

0 Answers
Related