Guest User

Untitled

a guest
Jan 17th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. /**
  2. * Add support for Field Group categories to Advanced Custom Fields (WordPress plugin).
  3. *
  4. * Drop this code into your theme's functions.php or equivalent file. This will
  5. * then allow you to add categories to Field Groups on the edit screen. It also
  6. * adds a "Category" column to the Field Groups list page - users can click
  7. * on the category name to filter the Field Groups by that category.
  8. *
  9. * @author Stefan Crowe <me@stefancrowe.co.uk>
  10. */
  11.  
  12. /**
  13. * Register ACF Field Group category
  14. */
  15. function register_acf_field_category()
  16. {
  17. $args = array(
  18. 'hierarchical' => true,
  19. 'public' => false,
  20. 'show_ui' => true,
  21. 'show_in_nav_menus' => true,
  22. );
  23.  
  24. register_taxonomy( 'acf-field-category', array( 'acf-field-group' ), $args );
  25. }
  26.  
  27. add_action('init', 'register_acf_field_category', 0);
  28.  
  29. function acf_field_group_columns($columns)
  30. {
  31. $columns['acf-field-category'] = __('Category');
  32.  
  33. return $columns;
  34. } // end function reference_columns
  35.  
  36. add_filter('manage_edit-acf-field-group_columns', 'acf_field_group_columns', 20);
  37.  
  38. function acf_field_group_columns_content($column, $post_id)
  39. {
  40. switch ($column) {
  41. case 'acf-field-category':
  42. global $post;
  43. $terms = get_the_terms($post->ID, 'acf-field-category');
  44.  
  45. if ($terms) {
  46. $term = array_pop($terms);
  47.  
  48. echo '<a href="?post_type=acf-field-group&acf-field-category=' . $term->slug . '">' . $term->name . '</a>';
  49. } else {
  50. echo '-';
  51. }
  52.  
  53. break;
  54. default:
  55. break;
  56. } // end switch
  57. } // end function reference_columns_content
  58. add_action('manage_acf-field-group_posts_custom_column', 'acf_field_group_columns_content', 20, 2);
Add Comment
Please, Sign In to add comment