Skip to content

Instantly share code, notes, and snippets.

@nfsarmento
Created July 2, 2020 15:56
Show Gist options
  • Select an option

  • Save nfsarmento/266086bbe4768c7aa7950b2c067bcd58 to your computer and use it in GitHub Desktop.

Select an option

Save nfsarmento/266086bbe4768c7aa7950b2c067bcd58 to your computer and use it in GitHub Desktop.
Display categories in single-cpt.php
<?php
if ( is_singular('YOUR_CUSTOM_POST_TYPE') ) {
$terms = get_the_terms($post->ID, 'custom_categories');
foreach ($terms as $term) {
$term_link = get_term_link($term, 'custom_categories');
if (is_wp_error($term_link))
continue;
echo '<a href="' . $term_link . '">' . $term->name . '</a>, ';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment