Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
isotope.category.codeblock.php
<?php
$categories = get_the_category(get_the_ID());
foreach( $categories as $category ) {
echo "<span class='category'>$category->slug</span>";
}
?>
@drjuanc

This comment has been minimized.

Copy link

@drjuanc drjuanc commented Jul 7, 2021

Hi there.
What if I´m using a custom post type, with custom taxonomies?

In that case, get_the_category doesn´t work.

But you can use get_the_terms function instead.

$category->slug"; } ?>
@joffreypersia

This comment has been minimized.

Copy link

@joffreypersia joffreypersia commented Nov 18, 2021

I tried :

<?php
	$categories = get_the_terms(get_the_ID(), 'my_acf_field');

	foreach( $categories as $category ) {
     
      echo "<span class='category'>$category->slug</span>";

  }
?>

But it doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment