So after 2 days of searching I found a solution.
Permalink manager lite + this function and all works fine.
//Rewrite rule
function pm_extra_permastructure_tags($default_uri, $native_slug, $post, $slug, $native_uri) {
// Do not affect native URIs
if($native_uri == true || empty($post->post_type) || $post->post_type !== 'mieszkanie') { return $default_uri; }
$inwestycja = get_field('inwestycja', $post->ID);
if( !empty($inwestycja) ) {
$inwestycjaObj = get_post($inwestycja);
$default_uri = str_replace('%mieszkanie_slug%', $inwestycjaObj->post_name, $default_uri);
}
return $default_uri;
}
add_filter('permalink_manager_filter_default_post_uri', 'pm_extra_permastructure_tags', 3, 5);
Related Posts:
- Taxonomy page returns 404 page not found
- Prepend meta_value to permalink of post
- Removing CPT slug from URL results in 404 error for archive page
- Getting Post ID from slug during init
- Interesting Custom Post Type Slug with Taxonomy and Custom Field
- Rewrite rules for custom post type slug
- How to remove slugs from multiple custom post types
- Change custom post type slug from plugin options
- Rewrite post type slug only for child theme
- Custom rewrite url category
- Index page with the same id as the slug
- How can I make the slug of the taxonomy also the slug of the custom post
- Programmatically rewriting slug through functions.php but returns 404
- Including taxonomy term before post type breaks top level pages
- WordPress Custom Post Type – Rewrite Query
- Custom Post Type Advanced Slug
- Custom Post Types and Removing Slugs – should we do it?
- Custom Post Type not using correct page template
- Add %post_id% to slug of custom post type and prevent the “unique slug” thing that WP does?
- Two CPT: one is using part of the custom rewrite slug from the other
- Custom Post Type Rewrite Rule
- Custom Post Type with multiple Custom Taxonomies / Hide Taxonomy Slug from URL
- Custom post type Premalinks main page and details page
- Custom slugs with dates & IDs on Custom Post Type
- Add post id to url instead of WordPress default -2 suffix
- Custom post type yearly/ monthly archive permalinks
- Meta_Query as a way how to setup CPT permalinks – is it a good thing?
- How can I rewrite URLs to pass taxonomy and post type values to the query?
- Using Custom Fields in Custom Post Type URL
- Removing base slug from hierarchical custom post type
- Rewriting ‘rewrite’ slug for custom post type used by plugin
- Adding meta values to permalink
- WordPress custom taxonomy URL rewrite on spelling errors
- How can i avoid the permalink start with ‘blog’ while using the custom post type?
- Custom Posttype Inheritance (and url structure)
- Adding %author% in custom post type URL structure?
- Post slug changed using code doesn’t reflect on editor when post is published
- Defining a default page for custom post type
- Pass parameter to custom post type single while keeping clean url
- Reslug a Custom Post Type
- Many to Many Taxonomies or rewrite rules?
- remove post-name from title in custom post type
- Rewrite custom post & taxonomy to share same URL path
- how to use two permalinks for one custom post type
- Custom post type’s slug gets wrong when adding a custom meta box
- Adding a date archive to Custom Post Type
- Bulk 301 redirect for custom post type
- Custom Permalink Tag breaks Pagination
- Custom Permalink with Dynamic Taxonomy for Custom Post Type – Works, but breaks other permalinks
- Custom Post Type and Custom Taxonomy Permalinks
- Pagination problem
- Custom post type with slug for plural (archive) and for single
- Custom Post Type Post have a Child `Page` Post Type Post
- remove permalink “front part” for custom post type
- Query var removed after rewrite
- Change Permalink Structure for Tag.php template
- Custom post types archive redirect
- Remove post type slug of all post types from permalinks
- Add archive slug to default post post type
- Custom Post type and permalink settings
- Am I using the flush_rewrite_rules function in the right place?
- Permalink for a custom post type isn’t working and I don’t know why
- Assign same parrent Page to pages AND custom post types
- WordPress custom post type permalink rewrite shows page not found
- Versioned Custom Post Type (Not the same as revisions)
- Custom post Type, child of a Page?
- Hide or disallow default custom post type url?
- Multiple (two) category postings on the same page.
- Custom taxonomy returns 404
- Pretty URLs and custom post types
- Specific routing for CPT
- Lost of query parameter when using permalink
- Slug for custom post type
- Custom Rewrite Rule for Custom Post Type with URL Param
- WordPress custom slug rewrite
- Dynamic CPT permalink structure based on ACF field value
- Rewrite rules for custom post type
- Custom taxonomy and post type rewrite rules
- Custom Post Type and Taxonomy Rewrite Error
- custom posts permalinks url rewriting
- Url Rewriting a dynamic wordpress page with parameters
- I want to rewrite the URL of a specific post with a specific custom field to easily analyze in Google Analytics
- Duplicate content problems after adding an archive page to the article’s post type
- Show code dependant on CPT & category
- Redirect Custom Post Type from Child Taxonomies
- Custom Post Type duplicating slug for new posts
- Custom post type rewrite and wp_pagenavi interfering with each other
- Generate slug and meta data if meta field is empty
- redirect old post type url to new structure url
- Why is a custom post type’s URL “/?cposts=name-of-the-post” but default post’s URL is “/?p=ID”?
- Ideal top-level slug methods
- How can you preserve URLs when moving posts to a custom post type?
- Custom Post Type Base URL
- Custom Post Type and single-posttype template
- Create page using same slug as custom post type
- Same slug for Custom Taxonomy archive and CPT archive – Rewrite rule not working
- How to rewrite custom slugs that follow my rules
- What is the best way to relate different custom post types?
- Allow child pages with the same base as the CPT slug
- Custom Post Type slug has the same Redirection entry