Pregunta

Estoy usando Cherry Framework en un sitio WP.Viene con un tipo de publicación personalizada que se puede usar para agregar 'Miembros del equipo' y crear páginas de personal, etc.

Necesito expandir esto para poder agregar etiquetas a cada 'miembro del equipo' para poder etiquetarlos esencialmente como trabajando en un departamento a/b/c/etc.

El tipo de publicación personalizada se registra en el archivo theme-init.php 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');

Quiero agregar etiquetas a esto, de modo que cuando agregue un nuevo miembro del equipo, también pueda asignarlo a un departamento agregando una etiqueta relevante determinada.Actualmente, el cuadro del editor de etiquetas no aparece en la página Agregar nuevo/Editar.

Entonces, adapté el código anterior para incluir una taxonomía de registros como esta;

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

Sin embargo, todavía no aparece el cuadro de etiqueta en la página de edición en el administrador.

Cualquier ayuda al respecto será enormente apreciada.

¿Fue útil?

Solución

Parece que el problema estaba en papel en la parte de su ser un tema-init.php en el tema secundario que estaba sobrecargando partes del tema-init.php en el tema de los padres / marco de cereza.

Resolví el problema agregando el siguiente código en el tema-init.php de My Child Theme.

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

Otros consejos

Pruebe esto

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

Puedes ver que agregué el taxonomies parámetro al register_post_type función.

Aunque este código debería funcionar, puedes intentar crear la relación más tarde, con esto:

add_action('init', 'add_tax_post_rel');

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

puedes probar esto

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

puede ser esto te ayudará

Licenciado bajo: CC-BY-SA con atribución
scroll top