Pergunta

Eu estou usando a cereja do quadro em um local de WP.Ele vem com um custom post type, que pode ser usada para adicionar 'dos Membros da Equipe e criar equipe de páginas, etc.

Eu preciso expandir isso para que eu possa adicionar tags para cada membro da equipe' inorder que eu posso, essencialmente, marcá-los como trabalhar em um departamento a / b / c / etc.

O custom post type é registrado no theme-init.php arquivo usando este código;

/* 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');

Eu quero adicionar tags para isso, de modo que quando eu adicionar um novo membro da equipe, eu também posso atribuí-las a um departamento por meio da adição de um determinado tag relevante.No presente, as tag editor de caixa não aparece no adicionar novo / editar página.

Então, eu adaptei o código acima para incluir um registro de taxonomia como este;

/* 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');

No entanto, ainda não estou recebendo a marca da caixa, mostrando-se na página de edição em administração.

Alguma ajuda com isso será muito apreciada.

Foi útil?

Solução

Parece que o problema foi na parte de baixo para ser um theme-init.php no tema criança que foi overwritting partes do theme-init.php no pai / cereja framework tema.

Eu resolvido o problema adicionando o seguinte código para o meu filho o tema da 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
    )
);

Outras dicas

tente isso

register_taxonomy(
        'team_tag', 
        'team', 
        array( 
            'hierarchical'  => false, 
            'label'         => __( 'Tags', CURRENT_THEME ), 
            'singular_name' => __( 'Tag', CURRENT_THEME ), 
            'rewrite'       => true, 
            'query_var'     => true 
        )  
    );
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')
    )
);

Você pode ver que eu adicionei o taxonomies parâmetro para o register_post_type função.

Embora este código deve funcionar, você pode tentar criar a relação, mais tarde, com este:

add_action('init', 'add_tax_post_rel');

function add_tax_post_rel() {
    register_taxonomy_for_object_type('team_tag', 'team', 11);
}

Você pode tentar isso

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 
            )  
        );
}

Pode ser isto irá ajudar a você

Licenciado em: CC-BY-SA com atribuição
Não afiliado a wordpress.stackexchange
scroll top