Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Add support for Field Group categories to Advanced Custom Fields (WordPress plugin).
- *
- * Drop this code into your theme's functions.php or equivalent file. This will
- * then allow you to add categories to Field Groups on the edit screen. It also
- * adds a "Category" column to the Field Groups list page - users can click
- * on the category name to filter the Field Groups by that category.
- *
- * @author Stefan Crowe <me@stefancrowe.co.uk>
- */
- /**
- * Register ACF Field Group category
- */
- function register_acf_field_category()
- {
- $args = array(
- 'hierarchical' => true,
- 'public' => false,
- 'show_ui' => true,
- 'show_in_nav_menus' => true,
- );
- register_taxonomy( 'acf-field-category', array( 'acf-field-group' ), $args );
- }
- add_action('init', 'register_acf_field_category', 0);
- function acf_field_group_columns($columns)
- {
- $columns['acf-field-category'] = __('Category');
- return $columns;
- } // end function reference_columns
- add_filter('manage_edit-acf-field-group_columns', 'acf_field_group_columns', 20);
- function acf_field_group_columns_content($column, $post_id)
- {
- switch ($column) {
- case 'acf-field-category':
- global $post;
- $terms = get_the_terms($post->ID, 'acf-field-category');
- if ($terms) {
- $term = array_pop($terms);
- echo '<a href="?post_type=acf-field-group&acf-field-category=' . $term->slug . '">' . $term->name . '</a>';
- } else {
- echo '-';
- }
- break;
- default:
- break;
- } // end switch
- } // end function reference_columns_content
- add_action('manage_acf-field-group_posts_custom_column', 'acf_field_group_columns_content', 20, 2);
Add Comment
Please, Sign In to add comment