Skip to content

Instantly share code, notes, and snippets.

@paulhuisman
Last active November 20, 2015 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulhuisman/d9d2b3b428b9b4a44666 to your computer and use it in GitHub Desktop.
Save paulhuisman/d9d2b3b428b9b4a44666 to your computer and use it in GitHub Desktop.
ACF hooks
<?php
function acf_field_group_testing($content) {
global $pagenow, $current_screen;
if ($pagenow == 'post-new.php' || $pagenow == 'post.php' && isset($current_screen->post_type)) {
$content = change_order_for_field_group($content, $current_screen->post_type);
}
return $content;
}
add_action('acf/get_field_group', 'acf_field_group_testing');
function change_order_for_field_group($content, $post_type) {
$fg_order = get_redefined_field_group_ordering();
// Check if there's an updated menu_order or position for this field_group
$content['menu_order'] = isset($fg_order[$content['key']][$post_type]['menu_order']) ? $fg_order[$content['key']][$post_type]['menu_order'] : $content['menu_order'];
$content['position'] = isset($fg_order[$content['key']][$post_type]['position']) ? $fg_order[$content['key']][$post_type]['position'] : $content['position'];
return $content;
}
function get_redefined_field_group_ordering() {
return array(
// image field
'group_563087c76ba2a' => array(
'article' => array(
'menu_order' => -4,
'position' => 'acf_after_title'
),
'product' => array(
'menu_order' => 4,
'position' => 'normal'
),
'playlist' => array(
'menu_order' => 2,
'position' => 'acf_after_title'
),
),
// teaser field
'group_563087c76f81f' => array(
'article' => array(
'menu_order' => 5,
'position' => 'normal'
),
'product' => array(
'menu_order' => 2,
'position' => 'normal'
),
'playlist' => array(
'menu_order' => 1,
'position' => 'normal'
),
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment