Aleluhia !
it was because $type don’t use WPML function
Here is the code that works perfectly with WPML and translated slug :
// .html pour les customs posts
function rewrite_rules($rules) {
$new_rules = array();
foreach (get_post_types() as $t)
$new_rules[$t . '/(.+?)\.html$'] = 'index.php?post_type=" . $t . "&name=$matches[1]';
return $new_rules + $rules;
}
add_action('rewrite_rules_array', 'rewrite_rules');
function custom_post_permalink ($post_link) {
global $post;
if ( $post ) {
$type = get_post_type($post->ID);
$slug = apply_filters( 'wpml_get_translated_slug',$type,$type,'');
return home_url() . "https://wordpress.stackexchange.com/" . $slug . "https://wordpress.stackexchange.com/" . $post->post_name . '.html';
}
}
add_filter('post_type_link', 'custom_post_permalink'); // for cpt post_type_link (rather than post_link)
Related Posts:
- Remove slug from custom post type post URLs
- Redeclare/Change Slug of a Plugin’s Custom Post Type
- Custom Post Type Slug / Page Slug Conflict – Prevent use of reserved slug on page save?
- WPML with WP_Query serving up all 3 languages [closed]
- Custom Post type & Taxonomy URL structure
- custom slug for custom post type
- Slug Formatting : Acceptable Characters?
- Get list of all registered post types slugs
- Combining Multiple Taxonomies in one URL
- Taxonomy archive with same slug as custom post type?
- Custom Post Type With Different Views
- Taxonomy page returns 404 page not found
- Custom Post Type – Same Post Name, Different Post Type
- Priority for Categories, Tags, Taxonomies, Posts, Pages and Custom Posts with same url
- Setting a title on a Custom Post Type that doesn’t support titles
- Custom Post Type pagination when CPT ‘rewrite’ rule and a page have the same slug
- Remove Slug from Custom Post Type results in 404
- Force unique page slugs across all post types
- Custom Slug for a custom post type and default post
- Interesting Custom Post Type Slug with Taxonomy and Custom Field
- Rewrite CPT slug with two taxonomy slug instead of one
- Get slug to point to different content of the same post
- WP query by custom post type slug/name
- Remove Taxonomy Slug when No Taxonomy is Assigned to Custom Post Type?
- Custom Taxonomy breaking pages permalinks
- Using custom post type parent as slug
- Rewrite rules for custom post type slug
- Make slug as ID Number for custom post types
- How to remove slugs from multiple custom post types
- Custom post type and taxonomy slug issue
- Does WordPress limit the length of slug names for Post Meta or Terms?
- Wrong generated page_name/slug on first publish of custom post type
- Stop / prevent WordPress from updating permalinks of custom post type
- Append date to custom post type url slug
- CPT custom archive template does not get loaded
- Change custom post type slug from plugin options
- How to add a post slug to a url?
- How to target a specific custom post type post and its all children and grandchildren?
- Custom rewrite url category
- Allow duplicate slugs for custom post type with taxonomies
- Nested Custom Post Type or Custom Post Type Parents?
- Programmatically rewriting slug through functions.php but returns 404
- Create a custom php page and load it at a specific slug
- Custom Post Type with Same Page URL
- How to prevent a CPT’s slug and page slug from conflicting with each other?
- Custom Post Slug same as Parents Category Slug
- Including taxonomy term before post type breaks top level pages
- Auto Slug Generation for Custom Post type
- How to make a posttype show under a page hierarchy (example.com/page/posttype/entry)?
- Rename a slug label
- Slug Confusion Between Post and Custom Post types?
- How to find a specific post_type using its “rewrite slug”?
- Different slug taxonomy for two different CPT
- How to add current custom taxonomy slug to body class
- Change Slug of a Custom Post Type
- How can Custom Post Type and a page have the same slug?
- How to get postname in custom page?
- Why WordPress is picking archive.php instead of page.php?
- Changing slug of all posts
- WordPress different templates for same type custom post (but different slug)
- Custom Post Type Advanced Slug
- Apply template by path/slug related to custom post type?
- Custom Post Type to replace Woocommerce products – page not found error
- Custom Post Type for Shortcode Use – Prevent it display as a post (with slug)
- Custom Post Types and Removing Slugs – should we do it?
- Need to return a string as permalink insted of str_replace
- How to controll the Posts post type and general wondering about WP data structure
- Under What Conditions Can I name my CPT the same as my CPT Page?
- How do I set a post slug automatically based on taxonomy?
- Custom rewrite rule based on other custom post type title
- Use custom post type taxonomy between cpt slug and name
- Remove custom taxonamy slug with pagination
- Custom Post Type not using correct page template
- WordPress doesn’t respect Page slug in custom post type url pagination. Keeps getting removed
- Add %post_id% to slug of custom post type and prevent the “unique slug” thing that WP does?
- Output all terms slugs for a loop filter
- Custom Post Type slug and WPML gets 404 error
- Custom post type URL structure with site.com/custom_taxonomy_slug/post_name
- Custom post type post_type_link gives “page not found” on any other custom post type
- Two CPT: one is using part of the custom rewrite slug from the other
- Custom permalink rewrite rules – how do I fix this?
- Custom taxonomy archive slug overwrites static page
- Slugs on hierarchical taxonomies
- Problem to get the link of the default ‘post’ post type like the orther custom types
- Can I override the permalink/slug on creation
- Get the custom post type slug but remove the rewrite prefix?
- Rewriting archive page slug to be different than custom post type slug
- Get full control over custom post type url
- custom post type archive slug vs. custom page template
- Add category slug as class attribute in a link array
- Relationship with 2 custom post types
- Can’t make permalink of CPT work
- How to make nested custom post type slugs work
- WP Query Post Type with same Taxonomy name
- Is this the correct way to add post-slug input field?
- WordPress pagination URL
- Fatal Error WordPress Custom Post Type UI + WPML
- Same slug for Custom Taxonomy archive and CPT archive – Rewrite rule not working
- Removing custom post type name from permalink
- Custom Post Type slug has the same Redirection entry