Skip Navigation

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.

Tagged: 

This topic contains 9 replies, has 2 voices.

Last updated by Subash Chandra Poudel 10 months, 2 weeks ago.

Assisted by: Subash Chandra Poudel.

Author Posts
May 22, 2023 at 11:10 pm #13694047

simonR-41

I am trying to:

Use the Yoast Duplicate Post "Rewrite and Republish" feature, along with schedule

Link to a page where the issue can be seen: N/A

I expected to see:

Post being published according to scheduled time, and all associated language posts remain connected. And Taxonomies, particularly categories remain unchanged.

Instead, I got:

I am using the Yoast Duplicate Post "Rewrite and Republish" feature for a CPT, and then scheduling the post for a future release which is done via Cron.

During this process, the post that has been branched from the original overwrites the original as expected, however its categories are changing, and all of the associated language versions, loose their taxonomy order.

After the republish the alternative language assumes the same taxonomy as the original posts

The only fix is to go into each of the associated language posts, add back the category and click update, which fixes the issue, however its not ideal as the scheduled posts can be published out of standard hours.

In this case the child category is a translated version
Child category = File Transmitter = ファイルトランスミッタ

images

schedule-1 , -2 and -5 are from before the schedule publish time.

And schedule-6, and -7 are after, and you can see in schedule-7 the categories have been altered.

This is breaking front end queries, and looks as if there are duplicates (multiple language)
__

Note that this site has been inherited from another agency, and its difficult to determine the cause of this issue, i.e. something has not been setup correctly.

schedule-8.PNG
schedule-7.PNG
schedule-6.PNG
schedule-5.PNG
schedule-2.PNG
schedule-1.PNG
May 23, 2023 at 12:15 am #13694245

simonR-41

It looks as if the category translation is set up properly.

schedule-9.PNG
May 23, 2023 at 5:26 am #13694507

simonR-41

I've decided to debug further, and look at the code and database prior to the reschedule and republish.

It appears that when programmatically getting the term by a different language that its not aligned with what is in the database.

Do you know of a way to check, or sync, or correct it?

____

Ive added this code to header.php, knowing that some of these methods are not intended to be called directly, however I want to demonstrate the results.

```
<?php
echo '<pre>';
/** @var WPML_Term_Translation $wpml_term_translations */
global $wpml_term_translations;

$term_id = 8141;
$lang_code = 'ja-jp';
$original_fallback = true;

$adjust_ttid_for_term_id = $wpml_term_translations->adjust_ttid_for_term_id( $term_id );
$element_id_in = $wpml_term_translations->element_id_in( $wpml_term_translations->adjust_ttid_for_term_id( $term_id ), $lang_code, $original_fallback );
$adjust_term_id_for_ttid = $wpml_term_translations->adjust_term_id_for_ttid( $element_id_in );
$term_id_in = $wpml_term_translations->term_id_in( $term_id, $lang_code, $original_fallback );
$translated_term_id = wpml_object_id_filter( $term_id, 'category', true, $lang_code );

var_dump( $adjust_ttid_for_term_id );
var_dump( $element_id_in );
var_dump( $adjust_term_id_for_ttid );
var_dump( $term_id_in );

echo '<pre>';

die();
```

The results are

header.php:16: string(4) "8192"
header.php:17: int(8192)
header.php:18: string(4) "8141"
header.php:19: string(4) "8141"
header.php:20: int(8141)

What I expect is that 8192 should be 8146, as per the links in the admin area, see this picture, and you can ignore the ACF field, it's not in use.

So it appears that the connected taxonomy may be incorrect during frontend processes, so i am not sure how it appears to be connected within WP Admin.

wpml-terms.PNG
May 24, 2023 at 11:28 am #13706521

Subash Chandra Poudel

Hi there,

Thank you for contacting WPML Support.

The code snippet you shared above to debug the issue is not referenced to our WPML Hooks reference ( https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/ )

Can you please let me know where exactly or how exactly did you built the code with? Please note our support is fairly limited when it comes to custom code but thank you a lot for sharing the details of your debugging result.

Regarding the main issue, I setup a test sandbox site to troubleshoot the issue further. Can you please login to the sandbox site using the next link, setup WPML and your plugins with as minimal data and setup as possible then test the Yoast Duplicate Post "Rewrite and Republish" feature to see if the issue can be replicated there?

hidden link

Regards,
Subash

May 29, 2023 at 12:08 am #13728637

simonR-41

Hi,

I am currently dealing with 2 issues, the first you may be able to help with.

1. Rewrite & Republish, incorrect category
I've taken a recording of the category issue and the steps I take to reproduce,
hidden link

2. Front-end Template Query
The code that I added is simply to see what WPML is doing at each step.
Within the template I imagine the implementation I want is;

$translated_term_id = wpml_object_id_filter( $term_id, 'category', true, $lang_code );

I would expect it to return the translated ID, however, its actually just returning the the default $term_id passed in.

This is because the following piece of code is executed as part of the wpml_object_id_filter function's process, and it is finding and returning an incorrect term ID that doesn't have any relationship to the original $term_id passed in. So it never correctly returns the translated version of the term id.

$wpml_term_translations->element_id_in( $wpml_term_translations->adjust_ttid_for_term_id( $term_id ), $lang_code, $original_fallback );

Ive been able to test this in the sandbox and I cannot duplicate the issue, you can see this by logging in and accessing hidden link. So it appears to be the database/code I am working with.

If you could assist me with the first problem please.

Regards

May 29, 2023 at 3:46 pm #13733945

Subash Chandra Poudel

Hi there,

Thank you for the details.

So, you said "Ive been able to test this in the sandbox and I cannot duplicate the issue"

So the second issue you said is not replicable on the sandbox site? If you need further help on the issue other than reported in the main post of this thread I recommend you to open new ticket as we try to handle only one issue per ticket to keep better track of the issue and stay on the same page.

Now, lets focus on the first issue, I am still a bit confused on the exact workflow/process of your issue. Can you please let me know the exact step by step process on how I can replicate the issue on any sandbox site or let me know the steps /URLs to see the issue on the sandbox site hidden link ?

Regards,
Subash

May 30, 2023 at 2:08 am #13735713

simonR-41

Hi Subash,

I shared a recording of the steps I took to replicate the bug on your sandbox site


1. Rewrite & Republish, incorrect category
I've taken a recording of the category issue and the steps I take to reproduce,
hidden link

May 30, 2023 at 5:04 pm #13741461

Subash Chandra Poudel

Hi there,

Thank you for your detailed video explanation.

I test this further on a different sandbox site and it can be replicated with normal posts and categories as well when using cron to run the missed schedule.

I have now escalated the issue to our 2'nd tier team. I will send you an update here as soon as we have an update from the team. It could however take some time as the issue seems to be an edge case issue and needs some time to test and troubleshoot.

Thank you for your co-operation and patience in the mean time.

Regards,
Subash

May 30, 2023 at 11:30 pm #13742825

simonR-41

Thanks for the update Subash, I look forward to your teams response.

June 6, 2023 at 4:14 pm #13780619

Subash Chandra Poudel

We have an update here! Our team has identified the issue and the issue has now been escalated to our Development team for a fix in the future release of WPML.

As a workaround for now can you please:

- Backup the site completely to prevent any issues.
- Edit the file wp-content\plugins\duplicate-post\src\post-duplicator.php in your WordPress directory.
- On line 189-190 find the following code:

// Clear default category (added by wp_insert_post).
\wp_set_object_terms( $new_id, null, 'category' );

- Replace the code with the following code instead:

// WPML Workaround for compsupp-6802
add_filter( 'wpml_disable_term_adjust_id', '__return_true' );

// Clear default category (added by wp_insert_post).
\wp_set_object_terms( $new_id, null, 'category' );
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.