-
-
Save certainlyakey/2863cb69f04c89766fc711435509fed6 to your computer and use it in GitHub Desktop.
Wordpress and Polylang: prevent certain custom fields' values from synchronising between posts in different languages (they always sync by default)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// We could use wpml-config.xml to turn off the sync, but it wouldn't support repeater-like fields | |
function themeprefix_dont_sync_specific_fields( $metas ) { | |
$unsync = array( | |
'office_country', | |
'uspage_liftups_repeater' | |
); | |
// Support for repeaters, flexible content fields etc. | |
if ( is_array( $metas ) && is_array( $unsync ) ) { | |
// loop over all passed metas | |
foreach ( $metas as $key => $value ) { | |
// loop over each unsynced item | |
foreach ( $unsync as $find ) { | |
if ( strpos( $value, $find ) !== false ) { | |
unset( $metas[$key] ); | |
} | |
} | |
} | |
} | |
return $metas; | |
} | |
add_filter( 'pll_copy_post_metas', 'themeprefix_dont_sync_specific_fields' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment