0

I'm using the cherry framework on a WP site. It comes with a custom post type that can be used to add 'Team Members' and create staff pages etc.

I need to expand this so that I can add tags to each 'team member' inorder that I can essentially tag them as working in a department a / b / c / etc.

The custom post type is registered in the theme-init.php file using this code;

/* Our Team */
function my_post_type_team() {
register_post_type( 'team',
    array(
        'label'               => theme_locals("our_team"),
        'singular_label'      => theme_locals("our_team"),
        '_builtin'            => false,
        // 'exclude_from_search' => true, // Exclude from Search Results
        'capability_type'     => 'page',
        'public'              => true,
        'show_ui'             => true,
        'show_in_nav_menus'   => false,
        'menu_position'       => 5,
        'menu_icon'           => ( version_compare( $GLOBALS['wp_version'], '3.8', '>=' ) ) ? 'dashicons-businessman' : '',
        'rewrite'             => array(
                                    'slug'       => 'team-view',
                                    'with_front' => FALSE,
                                ),
        'supports' => array(
                        'title',
                        'editor',
                    'thumbnail',
                    )
    )
);
}
add_action('init', 'my_post_type_team');

I want to add tags to this, so that when I add a new team member, I can also assign them to a department by means of adding a given relevant tag. At present the tag editor box doesn't appear on the add new / edit page.

So, I adapted the above code to include a register taxonomy like this;

/* Our Team */
function my_post_type_team() {
register_post_type( 'team',
    array(
        'label'               => theme_locals("our_team"),
        'singular_label'      => theme_locals("our_team"),
        '_builtin'            => false,
        // 'exclude_from_search' => true, // Exclude from Search Results
        'capability_type'     => 'page',
        'public'              => true,
        'show_ui'             => true,
        'show_in_nav_menus'   => false,
        'menu_position'       => 5,
        'menu_icon'           => ( version_compare( $GLOBALS['wp_version'], '3.8', '>=' ) ) ? 'dashicons-businessman' : '',
        'rewrite'             => array(
                                    'slug'       => 'team-view',
                                    'with_front' => FALSE,
                                ),
        'supports' => array(
                        'title',
                        'editor',
                    'thumbnail',
                    )
    )
);
register_taxonomy(
    'team_tag',
    'team',
    array(
        'hierarchical'  => false,
        'label'         => theme_locals("tags"),
        'singular_name' => theme_locals("tag"),
        'rewrite'       => true,
        'query_var'     => true
    )
);
}
add_action('init', 'my_post_type_team');

However, I'm still not getting the tag box showing up on the edit page in admin.

Any help with this will be greatly appreciated.

  • What is the function of these theme_locals – Pieter Goosen Sep 9 '14 at 12:40
  • @PieterGoosen Ive no idea to be honest. They must be part of the framework (cherry framework). – Phill Healey Sep 9 '14 at 13:35
1

It seems the issue was in part down to their being a theme-init.php in the child theme which was overwritting parts of the theme-init.php in the parent / cherry framework theme.

I resolved the issue by adding the following code into my child theme's theme-init.php;

register_taxonomy('team_tag', 'team', array(
    'hierarchical' => false, 
    'label' => theme_locals("tags"), 
    'singular_name' => theme_locals("tag"), 
    'rewrite' => true, 
    'query_var' => true
    )
);
1

try this

register_taxonomy(
        'team_tag', 
        'team', 
        array( 
            'hierarchical'  => false, 
            'label'         => __( 'Tags', CURRENT_THEME ), 
            'singular_name' => __( 'Tag', CURRENT_THEME ), 
            'rewrite'       => true, 
            'query_var'     => true 
        )  
    );
  • 1
    Please add proper answers, that is, if you add code, explain what your code does andhow it works. Thanks – Pieter Goosen Dec 1 '15 at 8:49
  • This does have nearly identical code without an opaque function definition that users don't have access to. In many ways this should be the code used in the accepted answer as it applies to all WP, not just cherry framework if there is no code comment or function definition. It even prompted a question from you. – MrMesees Jun 13 '17 at 12:03
0
register_post_type( 'team',
    array(
        'label'               => theme_locals("our_team"),
        'singular_label'      => theme_locals("our_team"),
        '_builtin'            => false,
        // 'exclude_from_search' => true, // Exclude from Search Results
        'capability_type'     => 'page',
        'public'              => true,
        'show_ui'             => true,
        'show_in_nav_menus'   => false,
        'menu_position'       => 5,
        'menu_icon'           => ( version_compare( $GLOBALS['wp_version'], '3.8', '>=' ) ) ? 'dashicons-businessman' : '',
        'rewrite'             => array(
                                    'slug'       => 'team-view',
                                    'with_front' => FALSE,
                                ),
        'supports' => array(
                        'title',
                        'editor',
                    'thumbnail',
                    ),
        'taxonomies' => array('team_tag')
    )
);

You can see that I added the taxonomies parameter to the register_post_type function.

Although this code should work, you could try creating the relation later, with this:

add_action('init', 'add_tax_post_rel');

function add_tax_post_rel() {
    register_taxonomy_for_object_type('team_tag', 'team', 11);
}
  • Thanks for the answer, but that doesn't do anything. If I change 'team_tag' to 'tag' and then add 'tags' to the support array, I get the tag box in the submenu and on the editor page. however this uses the sitewide tags. – Phill Healey Sep 9 '14 at 12:26
  • @PhillHealey can't be, the build-in tags are under the taxonomy post_tag, not tag – Pieter Goosen Sep 9 '14 at 12:42
  • @PhillHealey, I added an alternative way to create the relation. – Tomás Cot Sep 9 '14 at 12:57
  • @PieterGoosen Ok, it uses the same tags as another custom post type then. – Phill Healey Sep 9 '14 at 13:18
0

You can try this

add_action( 'init', 'create_client_tax' );
function create_client_tax() {
    register_taxonomy( 
            'client_tag', //your tags taxonomy
            'client',  // Your post type
            array( 
                'hierarchical'  => false, 
                'label'         => __( 'Tags', CURRENT_THEME ), 
                'singular_name' => __( 'Tag', CURRENT_THEME ), 
                'rewrite'       => true, 
                'query_var'     => true 
            )  
        );
}

May be this will help you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.