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.
Related Posts:
- get_term_by not working when in functions.php
- Can I turn off write-in tags/taxonomies?
- Formating the_terms() function output
- Scheduling posts to update once per day with wp_cron
- Possible to register multiple custom taxonomies in one function?
- How do I display a tag cloud with both post tags AND a custom taxonomy?
- Can I turn off write-in tags/taxonomies?
- How do I add customize_register action AFTER adding a custom taxonomy
- Adding ‘active’ class to custom taxonomies using walker in functions.php
- Check if term is in a taxonomy?
- get_terms not returning any custom taxonomies
- Display formatted list of taxonomy terms with last seperator different
- How to call a custom taxonomy term name inside a function?
- Update Post Taxonomy Automatically Based On Date
- Taxonomy archive template not working
- Running a function only once when a taxonomy term is changed
- How to add meta fields to custom taxonomy add/edit page?
- WordPress shortcode Issue!
- Automatically Populate Post Taxonomy Data Based on Post Author Meta Data?
- Where to put code to get custom taxonomy term id?
- I’ve got a function that auto creates taxonomy terms – Can it auto delete them as well?
- Remove taxonomy base or term from url
- Bulk term assignment for attachment taxonomies
- Why is my working Custom Taxonomy not in get_taxonomies array?
- Taxonomy slug by term ID
- How to enable hierarchical permalinks for hierarchical taxonomies
- Create taxonomy with meta term using the WP Rest Api
- Use custom posts as taxonomy term meta replacement?
- Remove description in custom taxonomy edit screen
- Taxonomies not appearing in columns on dashboard
- How to output the taxonomy term name in a widget
- Make Custom Taxonomy Category Use Parent Template
- How to call custom taxonomy categories with shortcodes
- How to get terms of a custom post type in a loop inside footer.php
- Is It Possible To Have Shared WordPress Custom Post Types?
- How do I make a custom taxomony appear like tags?
- Refine user taxonomy query based on role
- Get ID and slug from taxonomy object
- List the number of posts for each custom taxonomy and specific custom field value
- How can I conditionally change the title of a taxonomy meta box?
- Recreating the hierarchy of taxonomies for a dropdown form menu?
- meta_key & meta_value not working with get_pages and custom taxonomy
- showing custom taxonomies w/custom post type
- Display sub categories and their data of a taxonomy
- Exclude Taxonomy Terms from Template Via Back End?
- Insert HTML inside link in a walker
- How to overwrite registered taxonomy url from vendor plugin in child theme
- Dynamic loading of Archive content based on custom taxonomy term name
- Checking return with WP Error
- Add multiple taxonomy filters to edit.php that support search
- Set taxonomy fields on post with AJAX
- Custom Taxonomy index/archive hierarchy
- Parse error after modifying the template menu [closed]
- Show related posts that match two categories
- Failure to add term meta
- Removing “s” from search with custom parameters
- get_term_children returns unknown int though term has no child
- Custom taxonomy pagination
- Get the taxonomy of the post
- Custom taxonomy not showing terms in post area
- Problem with wordpress pagination
- link directly to custom post if there is only one in the taxonomy
- Add a term to list in block editor taxonomy sidebar
- Show only the sub-categories (and their content) of the current custom taxonomy with ‘taxonomy.php’
- WordPress modify Settings > Permalinks (options-permalink.php) Add CPT Permalink Options
- How do I make multiple dependent input fields that use the jquery autocomplete function?
- Also show terms that are related to draft and pending posts
- Breaking Bootstrap Grid at Post Count with Tax Terms
- Custom taxonomy page not working
- What is the best way to change sidebars based on custom taxonomy terms?
- Displaying the post count of all custom taxonomy terms in a list format
- How to update post taxonomies (Creating a custom UI for Custom Taxonomy)
- Taxonomy dropdown metabox in the back-end
- Taxonomy archive uses incorrect template when query strings are used
- wordpress mysql / wpdb ajax load more for terms help
- Get child product categories from parent product category for CUSTOM TAXONOMY archive page
- How to get related taxonomies based on a category with mysql query?
- Reorder a page of posts of a certain taxonomy/value by a custom field
- Get children of taxonomies
- Yoast – Custom Taxonomy – primary category
- List all taxonomies with their descriptions
- ACF Field, hide taxonomy title and image when no nothing selected in post
- Unregistered taxonomy apears still as emtpy filter list
- How to pass posts_per_page and paged params query vars to custom taxonomy archive urls?
- How to paginate with an query var appended to permalink?
- Use custom taxonomy terms as parent for pages
- Custom taxonomy return 404
- switch statement for taxonomy content
- How to include child terms within parent?
- create taxonomy
- Displaying Custom Taxonomy List Posts By Slug?
- Show different sidebar on taxonomy pages when a default is set
- How can I get parent term from a child term
- Custom Taxonomy – Archive for the whole Custom Taxonomy (and not just single term)?
- ACF Display Taxonomy Image Field
- Guest author – URL, base and custom taxonomy – working but unstable
- Taxonomy to display form after creation
- How home my code doesn’t display any feature image? Looping through post from a taxonomy and not getting feature images back
- Add taxonomy fields of posts into RSS feed
- Add text in custom taxonomy