• Resolved widescreen

    (@widescreen)


    Hi Maciej!
    I have my Permastructure like:

    custom post type : myslug-en/%posttype%

    When I enter a translation, I manually click on Permalink and change
    myslug-en/french title in myslug-fr/french title

    Now i don’t know what happened , maybe after the latest update Version 2.0.5.8,
    it changed all my Uri in
    myslug-en/french title

    I have 2 questions:
    1) Is there a way to fix this without go to the back up?

    2) Is there a way to do a conditional rewrite like:
    if it’s english > myslug-en/…
    if it’s french > myslug-fr/…

    Thanks!!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Maciej Bis

    (@mbis)

    Hi again @widescreen,

    I guess that the serialized array with custom URIs (‘permalink-manager-uris’ option in wp_options table) were malformed when you did find&replace.

    When it comes to conditional permastructures – yes, it is possible, but a custom code snippet will be needed:

    function pm_translate_post_uris($default_uri, $native_slug, $element, $slug, $native_uri) {
    	if($native_uri) { return $default_uri; }
    	// Get language details
    	$args = (!empty($element->ID)) ? array('element_id' => $element->ID, 'element_type' => $element->post_type) : array('element_id' => $element->term_id, 'element_type' => $element->taxonomy);
    	$lang_code = apply_filters('wpml_element_language_code', null, $args);
      
    	// Replace the base if German language is detected
    	if(!empty($lang_code) && $lang_code == 'fr') {
    		$default_uri = str_replace('myslug-en', 'myslug-fr', $default_uri);
    	}
    	return trim($default_uri, "/");
    }
    add_filter('permalink_manager_filter_default_post_uri', 'pm_translate_post_uris', 10, 5);
    add_filter('permalink_manager_filter_default_term_uri', 'pm_translate_post_uris', 10, 5);
    • This reply was modified 6 years, 11 months ago by Maciej Bis.
    Thread Starter widescreen

    (@widescreen)

    Hi Maciej!
    Thanks a lot!

    I will for sure try the snippet! A part from ‘myslug-en’, ‘myslug-fr’ is there anything else I have to change in the snippet? (I don’t want to make mistakes!!)

    Last 2 questions:
    1) I see you use ‘apply_filters(‘wpml_element_language_code’… Can I use the exactly same code with Polylang?
    2) Will it affect all posts or only my custom_post_type?

    Thanks I really appreciate!

    Plugin Author Maciej Bis

    (@mbis)

    Hi,

    No, that is the only thing that needs to be changed. Polylang supports this filter so it can be used with either WPML or Polylang. This will affect all default permalinks for all post types.

    Thread Starter widescreen

    (@widescreen)

    Thanks Maciej!!
    For now I created a script to replace myslug-en with myslug-fr, in all french posts.
    I placed it in permalink-manager-uri-editor-post.php
    It’s a quick fix, just to have the site running, before I will insert your snippet.

    I will share it here for anybody who needs it.
    [maybe it would be nice to have a couple of fields where you can do replace THISWORD, with THATWORD, for post in THISLANGUAGE]
    [I know you have the find&Replace tool, it’s good, but it’s not conditional and, if you have a loooot of posts, you get a memory error]

    Here is my humble piece of code:

    <button onclick=”correctUri()”>Replace bad French URis</button>
    <br /><br />
    <script type=”text/javascript”>
    function correctUri(){
    jQuery(“#the-list > tr”).each(function() {
    var postlanguage = jQuery(this).find(“.item_title”).find(“.extra-info”).find(“span:eq(2)”).text();
    var postID = jQuery(this).find(“.item_title”).find(“.row-actions”).find(“.id”).text(); if (postlanguage == “Language: fr”){
    oldURi = jQuery(this).find(“.item_uri”).find(“.custom_uri_container”).find(“.custom_uri”).val();
    mynewURi= oldURi.replace(“myslug-en”, “myslug-fr”);
    jQuery(this).find(“.item_uri”).find(“.custom_uri_container”).find(“.custom_uri”).val(mynewURi);
    }
    }); //each
    } //function
    </script>’;

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Changed all my URis!’ is closed to new replies.