-
-
Save Spellhammer/758135281eafee8d29ef05aac585c929 to your computer and use it in GitHub Desktop.
isotope.category.codeblock.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$categories = get_the_category(get_the_ID()); | |
foreach( $categories as $category ) { | |
echo "<span class='category'>$category->slug</span>"; | |
} | |
?> |
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.
You can try this if you want to use it with custom post types.
Just replace 'my_taxonomy' with your taxonomy.
<?php // Get terms for post
$terms = get_the_terms( $post->ID , 'my_taxonomy' );
// Loop over each item since it's an array
if ( $terms != null ){
foreach( $terms as $term ) {
echo "<span class='category'>$term->slug</span>";
// Get rid of the other data stored in the object, since it's not needed
unset($term);
} }
?>
Hi
I have a taxonmy 'location' where the user can select a location where the live, i put the code above in the repeater code block replacing 'my_taxonomy' with 'location' I then have 3 buttons with different locations, what code is used the the main code block?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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"; } ?>