Skip to content

Instantly share code, notes, and snippets.

@qstudio
Last active September 15, 2021 16:36
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save qstudio/dd0a1466f3b5c3af2591 to your computer and use it in GitHub Desktop.
Save qstudio/dd0a1466f3b5c3af2591 to your computer and use it in GitHub Desktop.
WP / PolyLang / Un-Sync Specified Custom Fields
<?php
// filter to exclude specified post_meta from Polylang Sync ##
add_filter( 'pll_copy_post_metas', 'q_pll_copy_post_metas' );
/**
* Remove defined custom fields from Polylang Sync
*
* @since 0.1
* @param Array $metas
* @return Array Array of meta fields
*/
function q_pll_copy_post_metas( $metas )
{
// this needs to be added to the PolyLang Settings page as an option ##
$unsync = array (
'team_player'
);
#var_dump( $unsync );
#var_dump( $metas );
if ( is_array( $metas ) && is_array( $unsync ) ) {
// loop over all passed metas ##
foreach ( $metas as $key => $value ) {
// loop over each unsynch item ##
foreach ( $unsync as $find ) {
if ( strpos( $value, $find ) !== false ) {
unset( $metas[$key] );
}
}
}
}
#wp_die( var_dump( $metas ) );
// kick back the array ##
return $metas;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment