Skip to content

Instantly share code, notes, and snippets.

@paulhuisman

paulhuisman/acf-hooks.php

Last active Nov 20, 2015
Embed
What would you like to do?
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