Skip to content

Instantly share code, notes, and snippets.

@sftsk
Forked from qstudio/pll_copy_post_metas.php
Created August 25, 2016 11:05
Show Gist options
  • Save sftsk/3da8e6c8aed9207792c930060690de80 to your computer and use it in GitHub Desktop.
Save sftsk/3da8e6c8aed9207792c930060690de80 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