Skip to content

Instantly share code, notes, and snippets.

@certainlyakey
Forked from qstudio/pll_copy_post_metas.php
Last active March 1, 2018 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save certainlyakey/2863cb69f04c89766fc711435509fed6 to your computer and use it in GitHub Desktop.
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)
<?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