1

I use a front end form to insert custom post types, an input is used for inserting terms (keywords) to a custom taxonomy for this custom post type.

I just noticed in the back-end when I view the terms list in the taxonomy. Only one unique term has been added even if I create multiple posts and use the same terms in each. Though in the back-end it does say how many custom posts the term is associated with.

From the back-end I get an error when trying to add a duplicate term. That's expected. I read though that WordPress in some cases creates a duplicate but the slug is unique.

On my custom post type single template page I have this function to list the terms

$keyword_terms = wp_get_object_terms($post->ID, 'keyword');
if(!empty($keyword_terms)){
  if(!is_wp_error( $keyword_terms )){
    echo '<ul>';
    foreach($keyword_terms as $term){
      echo '<li><a href="'.get_term_link($term->slug, 'keyword').'">'.$term->name.'</a></li>'; 
    }
    echo '</ul>';
  }
}

The slug / term link is the same on all the custom posts. Is that normal behavior of WordPress with custom taxonomies/terms? Is there a function to use to have the terms inserted and unique slugs generated?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.