0

This is my code that I used in the functions.php

add_action( 'init', 'register_cpt_video' );
function register_cpt_video() {
    $labels = array(
        'name'                      => __( 'Videos', 'video' ),
        'singular_name'             => __( 'Video', 'video' ),
        'add_new'                   => __( 'Añadir nuevo', 'video' ),
        'add_new_item'              => __( 'Añadir nuevo video', 'video' ),
        'edit_item'                 => __( 'Editar video', 'video' ),
        'new_item'                  => __( 'Nuevo video', 'video' ),
        'view_item'                 => __( 'Ver video', 'video' ),
        'search_items'              => __( 'Buscar videos', 'video' ),
        'not_found'                 => __( 'No se encontraron videos', 'video' ),
        'not_found_in_trash'        => __( 'No se encontraron videos en la papelera', 'video' ),
        'parent_item_colon'         => __( 'Parent Video:', 'video' ),
        'menu_name'                 => __( 'Video', 'video' ),
    );
    $args = array(
        'labels'                    => $labels,
        'hierarchical'              => false,
        'supports'                  => array( 'title', 'editor', 'thumbnail' ),
        'public'                    => true,
        'show_ui'                   => true,
        'show_in_menu'              => true,
        'menu_position'             => 5,
        'menu_icon'                 => 'dashicons-format-video',
        'show_in_nav_menus'         => true,
        'publicly_queryable'        => true,
        'exclude_from_search'       => false,
        'has_archive'               => true,
        'query_var'                 => true,
        'can_export'                => true,
        'rewrite'                   => true,
        'capability_type'           => 'post'
    );
    register_post_type( 'video', $args );

    $labels = array(
        'name'                  => _x( 'Categorías de video', 'Nombre de categoría de proyectos', 'video' ),
        'singular_name'         => _x( 'Categoría', 'Nombre de categoría de proyecto', 'video' ),
        'search_items'          => __( 'Buscar categorías', 'video' ),
        'all_items'             => __( 'Todas las categorías', 'video' ),
        'parent_item'           => __( 'Categoría superior', 'video' ),
        'parent_item_colon'     => __( 'Categoría superior:', 'video' ),
        'edit_item'             => __( 'Editar categoría', 'video' ),
        'update_item'           => __( 'Actualizar categoría', 'video' ),
        'add_new_item'          => __( 'Añadir nueva categoría', 'video' ),
        'new_item_name'         => __( 'Nueva categoría', 'video' ),
        'menu_name'             => __( 'Categorías', 'video' ),
    );
    register_taxonomy(
        'categoria-video', array( 'video' ), array(
            'hierarchical'          => true,
            'labels'                => $labels,
            'show_ui'               => true,
            'show_admin_column'     => true,
            'query_var'             => true,
        )
    );

    $labels = array(
        'name'                  => _x( 'Etiquetas de video', 'Nombre de etiqueta de proyectos', 'video' ),
        'singular_name'         => _x( 'Etiqueta', 'Nombre de etiqueta de proyecto', 'video' ),
        'search_items'          => __( 'Buscar etiquetas', 'video' ),
        'all_items'             => __( 'Todas las etiquetas', 'video' ),
        'parent_item'           => __( 'Etiqueta superior', 'video' ),
        'parent_item_colon'     => __( 'Etiqueta superior:', 'video' ),
        'edit_item'             => __( 'Editar etiqueta', 'video' ),
        'update_item'           => __( 'Actualizar etiqueta', 'video' ),
        'add_new_item'          => __( 'Añadir nueva etiqueta', 'video' ),
        'new_item_name'         => __( 'Nueva etiqueta', 'video' ),
        'menu_name'             => __( 'Etiquetas', 'video' ),
    );
    register_taxonomy( 
        'tag-video', array( 'video' ), array(
            'hierarchical'          => false,
            'labels'                => $labels,
            'show_ui'               => true,
            'show_admin_column'     => true,
            'query_var'             => true,
        )
    );
}

This is the code that I put in the single-video.php

<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
            <article>
                <h1><?php the_title(); ?></h1>
                <?php the_content(); ?>
                <div class="show_video">
                    <iframe src="https://www.youtube.com/embed/<?php echo get_post_meta(get_the_ID(),'datos_del_video_identificador',true); ?>" frameborder="0" scrolling="no" allowfullscreen></iframe>
                </div>
                <div class="info_video">
                    <div class="date_post">
                        <p><?php echo get_the_date(); ?></p>
                    </div>
                    <div class="category_post">
                        <p>Categoría: <?php get_the_category(); ?></p>

                    </div>
                </div>
                <div class="tag_list_post">
                    <?php get_the_tag_list(); ?>
                </div>
            </article>
            <?php endwhile; endif; ?>
  • You are using a custom taxonomy, category is not a generic thing, it is a built in taxonomy. – Milo Jan 25 '18 at 23:08
  • add 'taxonomies' => array( 'category' ), to your $args – admcfajn Jan 25 '18 at 23:16
0

get_the_category() is for getting the default post categories and get_the_tag_list() for the default post tags.

For custom taxonomies you must use get_the_terms(), i.e. get_the_terms( 'categoria-video' ) and get_the_terms( 'tag-video' ) in your case.

Note that these functions don't print anything, they just return an array. If you check out the documentation for get_the_terms() you'll find an example for displaying your terms though. In it's most simple form it would look like this:

$terms = get_the_terms( get_the_ID(), 'tag-video' );

if ( $terms && ! is_wp_error( $terms ) ) : 

foreach ( $terms as $term ) {
    echo $term->name;
}

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.