Print svg icon using $term_id

In my case CPT = event & Taxonomy = et-category & categories are green,red,black etc.

How to print svg icon for categories?

I am using if & else statement inside wp_query on index.php.

$today = date( ‘YmdH’ );
$args = array(
‘post_type’ => ‘event’,
‘posts_per_page’ => 30,
‘meta_key’ => ‘_end_eventtimestamp’,
‘orderby’ => ‘meta_value’,
‘order’ => ‘ASC’,
‘meta_query’ => array(
array(
‘key’ => ‘_end_eventtimestamp’,
‘value’ => $today,
‘compare’ => ‘>=’,
)
),
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while( $query->have_posts() ) {
$query->the_post();
the_title();
the_content();

if ($term_id = 10){
echo ‘<p class=”icon-gear”></p>’;
}
else if ($term_id = 11){
echo ‘<p class=”icon-star”></p>’;
}
else if ($term_id = 12){
echo ‘<p class=”icon-tv”></p>’;
}
//and continuous …………..
}
}

CSS

.icon-gear:before { background:url(‘gear.svg’) no-repeat; }
.icon-star:before { background:url(‘star.svg’) no-repeat; }
.icon-tv:before { background:url(‘tv.svg’) no-repeat; }

Read more here:: Print svg icon using $term_id

Leave a Reply

Your email address will not be published. Required fields are marked *