Skip to content

Instantly share code, notes, and snippets.

@solepixel
Created June 8, 2016 04:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save solepixel/e8f09b9ba781502f893274ff8bf6dcf1 to your computer and use it in GitHub Desktop.
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".
<?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