WPML Slug Conflicts

So I just started using WPML CMS on a site with a large number of custom post types. Everything was going fine, and the CMS editors were loving the ease of use.

Things were going smoothly until conflicting slugs started to happen. I’ll give you an example we had a page :

example.com/my-new-thing

which we linked to from our custom post type like so:

example.com/cpt/my-new-thing

Now a few things to note:

  1. The custom post type and the page are using the same slug
  2. Both do not have any translations

However wpml will redirect the page example.com/my-new-thing to example.com/cpt/my-new-thing ! I traversed their redirect code and I believe the issue is when they search by name and pagename they do not distinguish between post types which seems to simple to be the problem ??‍♂️

I haven’t figured it out completely but for now I’ve done what most other people have suggested which is remove the action based on the posts ID. I’m thinking if this becomes a common problem I might create a disable WPML checkbox in the editor.
If you by chance are struggling with slug conflicts with WPML obviously head to their support forums. If you are interested in what I did to fix my woes it was something along these lines:

function wpml_remove_parse_query_action( &$query ) {
    global $sitepress;
    if ($query->queried_object_id === ID_OF_PAGE) {
        remove_action( 'parse_query', array( $sitepress, 'parse_query' ) );
    }
}
add_action( 'parse_query', 'wpml_remove_parse_query_action', 5 );

I hope this helps you out. Otherwise, it’s just another rant by a WordPress developer.

What y’all thought

Have something to say?