Please make sure to update to WPML 4.3.6 and check our list of Known Issues before reporting

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Our next available supporter will start replying to tickets in about 4.05 hours from now. Thank you for your understanding.

This topic contains 31 replies, has 5 voices.

Last updated by Shekhar Bhandari 2 years, 3 months ago.

Assigned support staff: Shekhar Bhandari.

Author Posts
April 21, 2017 at 10:56 am #1258905

Henrik

I am trying to:
Get the updated posts new permalink on wp_insert_post (or post_updated).
But because of WPML_Slug_Translation not clearing it's post_link_cache I am getting the old permalink.

Steps to duplicate the issue:
Hook in to wp_insert_post and print the results of get_post_permalink($post)
Go to a custom post type and change it's permalink (the post might have to be on a second language), notice how the output of the get_post_permalink function is the old and not the new permalink.
The issue is only able to be duplicated if WPML_Slug_Translation has cached the old permalink so results may vary.

April 21, 2017 at 12:01 pm #1258954

Henrik

I was able to implement a temporary work around like this:

global $wpml_slug_translation;
// Disable post_type_link_filter
$wpml_slug_translation->ignore_post_type_link = true;
$new_permalink = get_permalink( $post_id );
// Enable post_type_link_filter
$wpml_slug_translation->ignore_post_type_link = false;
// Manually run post_type_link_filter, the 3rd and 4th arguments causes the cache signature to be different from the one in the cache.
$new_permalink = $wpml_slug_translation->post_type_link_filter($new_permalink, $post, 0, 0);

However this fix doesn't feel very future proof at all, a more permanent fix from the WPML team would be much appreciated.

April 24, 2017 at 3:56 am #1259862

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello @henrik,

Thank you for contacting WPML support. I'd be happy to help you on this.

Could you please provide me further details how you are using the wp_insert_post, are you using wp_insert_post for updating usage? Could you please provide me the whole code that you are using in pastebin.com so I can review it and replicate the issue if necessary?

I look forward to your reply.

Thanks

April 24, 2017 at 8:24 am #1259990

Henrik

https://pastebin.com/9U3JN7g7

The purpose of this code is to print the new URL to the error_log when a post is updated.
When updating the permalink of a custom post type however, the old permalink will be printed.
If you are not able to replicate the issue I would recommend trying to hook in to an action that occurs before save and then use the get_permalink function in there, this should cause the old permalink to be cached.

April 25, 2017 at 9:10 am #1261058

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hi there,

I am working on this issue and will post my feedback soon.

Thanks

April 25, 2017 at 10:27 am #1261131

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hi there,

I tested this code with few installations and I couldn't replicate the same issue as you explained as I am able to see the correct URL for the post.

I also tested the same with save_post action and it's printing me correct results. So, I would request you to test the issue on a new browser and clearing cache too.

Also, Please make sure you are using the latest version of WPML and its add-ons. We've released new versions that fix many bugs and errors for some days. You can compare between your site and here: http://wpml.org/my-account/downloads/

NOTE:
+ Make a backup (both files and database) for your site before updating/proceeding anything (Always a good practice!).
+ You need to update all your current WPML and its add-ons to the latest versions. If not, some unexpected problems may happen.

I look forward to your reply.

Thanks

April 25, 2017 at 11:06 am #1261171

Henrik

I have put together a plugin that will allow you to replicate the issue:
https://pastebin.com/N1C6nkyw

The following plugins are required:
- WPML Multilingual CMS 3.7.0
- WPML String Translation 2.5.3

The following settings need to be enabled:
- Make 'Example post type' translatable
- Translate custom posts slugs (via WPML String Translation).

I can also provide access to a testing site demonstrating the issue.

April 26, 2017 at 9:28 am #1262033

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hi there,

Sure, please provide me those details as well as clear steps to reproduce the issue to reproduce it as with the plugin you provided too, I don't find any issue in the future.

I need to request temporary access (wp-admin and FTP) to your site in order to be of better help. You will find the needed fields for this below the comment area when you log in to leave your next reply. hidden link

This info is private and available to you and supporters only. Read more about this: https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

Note that:
+ Backup (both files and database) your site before giving us your credentials
+ It would be better if you give me the test site rather than the live site.

We'd like to request the permission to disable, enable and install themes and plugins for this site. Please accept this?

I look forward to your reply.

Thanks

April 27, 2017 at 3:03 am #1262836

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hi there,

Ok, I tested this on your site and I can retrieve the new permalink there too, so I am confused where is the error. Could you please check this once again?

I look forward to your reply.

Thanks

April 27, 2017 at 8:55 am #1263038

Henrik

My bad, I had not translated the post slug. Which is needed to replicate the issue.
I have also updated the steps to reproduce, please check.

April 28, 2017 at 5:31 am #1263964

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hi there,

If you remove the following code from the above code you provided, the issue is not existing, so please remove this and try once.

add_action( 'pre_post_update', function() {
    get_permalink();
});

Look forward to your reply.

Thanks

April 28, 2017 at 11:28 am #1264230

Henrik

Yes, the point of the plugin is to demonstrate how to replicate the issue.

Please see the first paragraph of my first post in this thread for an explanation of why the issue occurs.

I believe I have provided enough information to allow a WPML developer to solve the issue.
If this is not the case I can provide WPML with a modified version of the WPML_Slug_Translation Class that does not have this issue.

May 1, 2017 at 9:14 am #1265323

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hi there,

I am discussing this issue with our 2nd tier supporters and will respond to you soon.

Thanks

May 3, 2017 at 12:11 pm #1267104

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hi there,

This is to inform you that I am still discussing this issue with our 2nd tier supporters and will respond to you soon.

Thanks

May 4, 2017 at 8:21 am #1267754

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hi @henrik,

After a lot of discussing and debugging our 2nd tier support suggest that you can use "save_post" hook instead of "post_updated" hook to get the correct permalink. They also suggested that WPML runs a lot of functions on the save_post hook so it will be nice to use this hook instead of post_updated.

Let me know if that helps.

Thanks