-
-
Save masato-igarashi/1fd2ec65816cc73f8c175b8272c4f78c to your computer and use it in GitHub Desktop.
WP / PolyLang / Un-Sync Specified Custom Fields
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 | |
// 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