Add or replace this to your register_taxonomy (in functions.php):
'query_var' => 'city',
'rewrite' => true
Then append this to your functions.php
add_filter('post_link', 'city_permalink', 10, 3);
add_filter('post_type_link', 'city_permalink', 10, 3);
function city_permalink($permalink, $post_id, $leavename) {
if (strpos($permalink, '%city%') === FALSE) return $permalink;
// Get post
$post = get_post($post_id);
if (!$post) return $permalink;
// Get taxonomy terms
$terms = wp_get_object_terms($post->ID, 'city');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $taxonomy_slug = $terms[0]->slug;
else $taxonomy_slug = 'not-rated';
return str_replace('%city%', $taxonomy_slug, $permalink);
}
Here you can find a more detailed description.
Related Posts:
- How to generate a list of all urls
- How does WordPress create URLs that Apache knows about?
- Stop WordPress appending `-2` to the end of my url after i change it
- Get current URL (permalink) without /page/{pagenum}/
- How to get pretty URLs with add_query_arg in permalinks
- Creating custom permalink structure for languages
- Adding another word in front of post url
- Permalink with sub-sub-category and post name
- Custom Taxonomy in Permalink of Post
- How to prevent apostrophes and quotes from appearing in permalinks?
- Update URL Snippet to Canonical Permalink URL
- why does anchor name add a slash to url?
- “.#[random-char-string]” being inserted at end of URLs
- How to create a permalink structure for posts in a specific category
- How to Remove Slug From Database?
- How to make draft posts or posts in review accessible via full url / slug?
- Remove subfolders from URL
- flexible rewrite ‘ramble’ URLs with WordPress
- Include Taxonomy slug in post url
- How to increase the character limit for post name of 200?
- Custom rewrite rules for feeds of custom queries (query_var query strings in URL)?
- Change website URL without breaking links or images? WP 3.3
- Remove Custom Taxonomy Slug from Permalink
- WordPress 3.4 Permalinks Redirection Problem
- Add a css class to a taxonomy permalink
- How to Modify Existing Rewrite Rules?
- Using ‘Primary Category’ in URL
- Can two products with the same name but different category produce unique URLs?
- echo post-permalink without http and www
- Confusion about how a URL is being parsed
- Get closest page ID from URL
- How to reset canonical URLs / fix redirect loop
- Setting up two separate blogs while using WordPress as a CMS
- How to show the homepage on a different url, like site.com/blog instead of site.com?
- wordpress api using rest_route for other pages
- Force wordpress to display page with same url structure as categories
- Possible to remove taxonomy from permalink if uncategorized?
- Is there a link parameter that will show me all my published pages?
- How can i have a custom post type with more slugs for each post?
- URL rewriting: removing the site’s basename for a specific category
- wordpress custom post type taxonomy permalink
- Get the url of a page template without using the page slug and ID
- WordPress keeps giving me the wrong permalink
- Host frontpage via example.com and everything else via example.com/blog
- WordPress can generate numeric permalinks, which then 404
- display dynamic content based on url slug on custom page
- Pre-populate Slug / Permalink with URL
- Relative v.s. absolute URLs: which ones should I use for cross-domain portability?
- How to use all tags in post permalinks
- Unique one time use URL
- cannot link a external url, present page url acting as parent url
- Remove parent page from url
- Problem with parent page slug only in WordPress admin
- Getting back a permalink from custom url
- “-2” Being added to end of URL (no duplicate pages, no pages in trash)
- Bulk append URL (add word to slug)
- Change permalinks for specific pages
- replacing post ID by custom post name in url
- Access posts while mod_rewrite is broken
- Remove international characters from slug – Almost done – Bit help
- Post with no tag permalink problem
- replicate url permalink after migrating to wordpress
- How to remove slug from front page?
- assets aren’t loading on a page but loads on others? slug permalink conflict?
- Multiple Taxonomy Items for Separate URLs
- WordPress keeps removing query var from the URL
- URL gives 404 error of my subfolder site when i change permalink
- Change Project permalink to custom URL
- How to construct a dynamic rewrite rule for child pages that passes more than one query var
- How to separate an overgrown blog into sub-blogs – without breaking existing inbound links?
- Using a template file for a specific custom URL
- Nested permalink without dummy parent page
- Extra url paths as variable
- Passing parameter through permalink structure
- Custom Taxonomy rewrite rule causes 404 error on page or single post depending on if it’s set to “True” or “False”
- How to create a standard WP Page that has the same url as an archive
- URL issue after setting up Custom Structure in Settings >> Permalinks
- Why does page for hierarchical taxonomy parent term go 404?
- rebuilding/ rewriting a url to make it SEO friendly
- How to change the URL using rewrite rule in wordpress
- Get value from URL with different types of parameters
- a way to support totally different url structure
- add bar in paging in the URL
- WordPress Page URL
- Remove/hide a specify category-name from the url
- How to change URL of my pages?
- Imported posts using wrong domain name
- When using number in url it is redircting to same page but when using character it redirects to 404
- Custom Post Type Categories Not Maintaining URL structure any more
- Custom Permalink Base
- Change permalink in wp-property
- Multiple Parent Category URLs
- Include language variable in url
- How to get the perfect WordPress, WooCommerce, Custom Post Type pretty permalinks?
- WordPress keep redirecting me to random URLs
- Not recognizing my custom templates in hierarchy
- Remove parent product category slug from product_cat url woocommerce
- Standard Htaccess directives disappear by themselves
- ‘Unsupported Operand Types’ error stemming from taxonomy re-writes with PHP 8.1
- Change default URL (or permalinks) in the back-end