Function code problem

If the code above is how it is in your actual theme file, there are obvious errors (maybe it didn’t post right here). Here is the fixed code:

<?php
add_filter('post_type_link', 'my_permalink_structure', 10, 4);
function my_permalink_structure($post_link, $post, $leavename, $sample) {
  if ( false !== strpos( $post_link, '%states%' ) ) {
    $term = get_the_terms( $post->ID, 'states' );
    $post_link = str_replace( '%states%', array_pop($term)->slug, $post_link );
    }
  return $post_link;
  }
?>

If that doesn’t help perhaps a link to the entire code would help.