Created
June 8, 2016 04:46
-
-
Save solepixel/e8f09b9ba781502f893274ff8bf6dcf1 to your computer and use it in GitHub Desktop.
Differentiate Settings Page fields when using the same field groups. Requires "menu_slug" prefixed with something common and identifiable, in this case the Post Type of the Archive as well as a common naming convention, in this example it uses "-archive-settings".
This file contains 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 | |
add_filter( 'acf/load_field', 'mytheme_set_field_name' ); | |
function mytheme_set_field_name( $field ){ | |
if( is_admin() ){ | |
$screen = get_current_screen(); | |
if( $screen->id == 'acf-field-group' ) | |
return $field; | |
$admin_screen = '-archive-settings'; | |
if( strpos( $screen->id, $admin_screen ) === false ) | |
return $field; | |
$page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; | |
$post_type = str_replace( $admin_screen, '', $page ); | |
} else { | |
$post_type = get_post_type(); | |
} | |
$field['name'] = '_' . $post_type . $field['name']; | |
$field['_name'] = $field['name']; | |
return $field; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment