$choice_label){ $return[$choice] = $choice_label; $return[$choice . '_archive'] = $choice_label . ' Archive' . ($choice == 'all' ? 's' : ''); } $choices = $return; return $choices; } /** * ACFE Location: Post Type Archive Save */ add_action('load-edit.php', 'acfe_location_post_type_archive_save'); function acfe_location_post_type_archive_save(){ // Enqueue ACF JS acf_enqueue_scripts(); // Success message if(isset($_GET['message']) && $_GET['message'] == 'acfe_post_type_archive') acf_add_admin_notice('Options have been saved', 'success'); // Verify Nonce if(!acf_verify_nonce('post_type_archive_options')) return; // Get post type global $typenow; // Check post type $post_type = $typenow; if(empty($post_type)) return; // Validate if(acf_validate_save_post(true)){ // Autoload acf_update_setting('autoload', false); // Post ID $post_id = $post_type . '_options'; // Languages Support $dl = acf_get_setting('default_language'); $cl = acf_get_setting('current_language'); if($cl && $cl !== $dl) $post_id .= '_' . $cl; // Save acf_save_post($post_id); // Redirect wp_redirect(add_query_arg(array('message' => 'acfe_post_type_archive'))); exit; } } /** * ACFE Location: Post Type Archive Footer */ add_action('admin_footer', 'acfe_location_post_type_archive_footer'); function acfe_location_post_type_archive_footer(){ // Check current screen global $pagenow; if($pagenow !== 'edit.php') return; // Get post type global $typenow; // Check post type $post_type = $typenow; if(empty($post_type) || !in_array($post_type, acf_get_post_types())) return; // Check location = All archives $field_groups_all = acf_get_field_groups(array( 'post_type' => 'all_archive', )); // Check location = Post type archive $field_groups_specific = acf_get_field_groups(array( 'post_type' => $post_type . '_archive' )); $field_groups = array_merge($field_groups_all, $field_groups_specific); // Check field groups if(empty($field_groups)) return; // Init field groups by position $field_groups_position = array( 'acf_after_title' => array(), 'normal' => array(), 'side' => array() ); foreach($field_groups as $field_group){ $field_groups_position[$field_group['position']][] = $field_group; } // Reset to $field_groups $field_groups = $field_groups_position; // Position: After Title if(!empty($field_groups['acf_after_title'])){ $total = count($field_groups['acf_after_title']); $current = 0; foreach($field_groups['acf_after_title'] as $field_group){ $current++; add_meta_box( // ID 'acf-' . $field_group['ID'], // Title $field_group['title'], // Render 'acfe_post_type_archive_render_mb', // Screen 'edit', // Position $field_group['position'], // Priority 'default', // Args array( 'total' => $total, 'current' => $current, 'field_group' => $field_group ) ); } ?>
$total, 'current' => $current, 'field_group' => $field_group ) ); } ?>
$total, 'current' => $current, 'field_group' => $field_group ) ); } ?>
'post_type_archive_options', 'post_id' => $post_id, )); // Fix WP media upload conflict with underscore.json_decode // Force basic uploader acf_update_setting('uploader', 'basic'); // Get fields $fields = acf_get_fields($field_group); // Render fields acf_render_fields($fields, $post_id, 'div', $field_group['instruction_placement']); if($current === $total){ ?>
'acf-' . $field_group['ID'], 'key' => $field_group['key'], 'style' => $field_group['style'], 'label' => $field_group['label_placement'], 'edit' => acf_get_field_group_edit_link($field_group['ID']) ); ?>