Set limitations of wp_update_post()?

It sounds like you’re facing an issue where using wp_update_post() in your function is unintentionally altering additional fields beyond the post_date and post_date_gmt. This can happen because wp_update_post() is designed to handle a complete post update, and it might modify other fields if they are not specified or handled correctly in your update array.

To limit the update to only post_date and post_date_gmt, you should ensure that your update array contains only these two fields. However, since you’re experiencing issues with other fields being altered, it suggests there might be some interference from other hooks or the way Polylang manages synchronized fields.

Here are a few steps you can take to troubleshoot and resolve this issue:

Disable Unwanted Synchronization in Polylang:
Polylang has synchronization settings that might cause additional fields to be synchronized when you update a post. Check your Polylang settings to ensure that only the fields you want are being synchronized across translations.

Modify the Function:
Ensure that your function explicitly specifies only the fields you want to update. This would look something like this:

function update_post($post_ID){
    $mpostid = pll_get_post( $post_ID, pll_default_language() );
    $timeD = current_time('mysql'); 
    if($post_ID == $mpostid) {
        $languages = pll_get_post_translations($mpostid);
        foreach (array_slice($languages, 1) as $language) {
            $updatess = array(
                'ID' => $language, 
                'post_date' => $timeD, 
                'post_date_gmt' => get_gmt_from_date( $timeD ),
                'edit_date' => true
            );
            wp_update_post( $updatess, true );
        } 
    }
}

Note the use of ‘edit_date’ => true in the $updatess array. This tells WordPress to only update the date fields.

Avoid Automatic Synchronization:
If Polylang is automatically synchronizing fields you don’t want to change, consider temporarily disabling these synchronization features while running your update function, then re-enabling them afterward.

Use Custom SQL Query:
If the standard WordPress functions continue to cause issues, you can directly update the database using a custom SQL query. This approach requires caution and a good understanding of the WordPress database structure. Here’s a rough example:

global $wpdb;
$languages = pll_get_post_translations($mpostid);
foreach (array_slice($languages, 1) as $language) {
    $wpdb->update( 
        $wpdb->posts, 
        array( 
            'post_date' => $timeD, 
            'post_date_gmt' => get_gmt_from_date( $timeD )
        ), 
        array( 'ID' => $language )
    );
}

This direct database approach bypasses the usual WordPress hooks and functions, so it’s less likely to trigger unintended changes.

Remember to back up your database before making direct changes, and test your function thoroughly in a development environment to ensure it behaves as expected.

deneme bonusudeneme bonusu veren sitelerpulibet girişOnwin Güncel Giriştürkçe altyazılı pornocanlı bahis casino