Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using this function, but it only shows one category.
PHP
// SingleNetwork
function SingleNetwork() {
	global $post;
	$term = get_the_terms( $post->ID, 'networks' );
	
	if ( ! is_wp_error( $term ) && ! empty( $term ) ) {
	
	$firstTerm = $term[0];
	$term_link = get_category_link($firstTerm->term_id);
	
	echo '<a href="' . $term_link . '" rel="tag">' . $firstTerm->name . '</a>';
	 
	}	
}

I would like to show 2 categories using the same function.
e.g
Category1 & Category2

What I have tried:

Try using the foreach.
foreach($terms as $term) {
if ($count < 2) {
Posted
Updated 2-Feb-23 15:10pm

1 solution

You can make the categories appear but I can't separate them using & e.g
Category1 & Category2

PHP
foreach ( $terms as $term ){
    if ($count term_id);

echo '' . $firstTerm->name . '','';
$count++;
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900