• I have some doubts about this, looked at various sites and still remains my doubts. Thank you in advance if anyone can help and I hope it is useful to more people.

    Well I made everything right according to a tutorial on custom post it to put my videos from youtube and also enter a METABOX, below is the code:

    question 1) First question is whether this code is safe?

    question 2) How do I create a category.php and make the pagination of posts? I’ve tried all the ways that the net and saw nothing, eg taxonomy-categories.php-videos, videos-categories.php, videos.php-categories, category-10.php.
    When I go to the link https://www.home.com / videos he sends me to the main page.
    The single-video.php worked perfectly.

    question 3) Do I have to create a category “videos” in >> Categories / Add New Category?

    <?php 
    
    add_action( 'init', 'create_post_type_video' );
    
    function create_post_type_video() {
    
        $labels = array(
    	    'name' => _x('Videos', 'post type general name'),
    	    'singular_name' => _x('Video', 'post type singular name'),
    	    'add_new' => _x('Adicionar Novo', 'video'),
    	    'add_new_item' => __('Adicionar Novo Video'),
    	    'edit_item' => __('Editar Video'),
    	    'new_item' => __('Novo Video'),
    	    'all_items' => __('Todos Videos'),
    	    'view_item' => __('Ver Video'),
    	    'search_items' => __('Pesquisar Videos'),
    	    'not_found' =>  __('Sem video'),
    	    'not_found_in_trash' => __('Sem Videos na lixeira'),
    	    'parent_item_colon' => '',
    	    'menu_name' => 'Videos'
        );
    
        register_post_type( 'video', array(
    	    'labels' => $labels,
    	    'public' => true,
    	    'publicly_queryable' => true,
    	    'show_ui' => true,
    	    'show_in_menu' => true,
    	    'has_archive' => 'videos',
    	    'rewrite' => array(
    		 'slug' => 'videos',
    		 'with_front' => false,
    	    ),
    	    'capability_type' => 'post',
    	    'has_archive' => true,
    	    'hierarchical' => false,
    	    'menu_position' => null,
    	    'supports' => array('title','editor','thumbnail')
    	    )
        );
    
        register_taxonomy( 'video_category', array( 'video' ), array(
            'hierarchical' => true,
            'label' => __( 'Video Category' ),
            'labels' => array( // Labels customizadas
    	    'name' => _x( 'Categories', 'taxonomy general name' ),
    	    'singular_name' => _x( 'Category', 'taxonomy singular name' ),
    	    'search_items' =>  __( 'Search Categories' ),
    	    'all_items' => __( 'All Categories' ),
    	    'parent_item' => __( 'Parent Category' ),
    	    'parent_item_colon' => __( 'Parent Category:' ),
    	    'edit_item' => __( 'Edit Category' ),
    	    'update_item' => __( 'Update Category' ),
    	    'add_new_item' => __( 'Add New Category' ),
    	    'new_item_name' => __( 'New Category Name' ),
    	    'menu_name' => __( 'Category' ),
    	),
            'show_ui' => true,
            'show_in_tag_cloud' => true,
            'query_var' => true,
            'rewrite' => array(
            'slug' => 'videos/categories',
            'with_front' => false,
            ),
            )
        );
    
        register_taxonomy_for_object_type( 'tags', 'video' );
    
    }
    
    add_action( 'add_meta_boxes', 'video_add_meta_box' );
    
    function video_add_meta_box() {
        add_meta_box(
            'video_metaboxid',
            'Atributos do Video',
            'video_inner_meta_box',
            'video'
        );
    }
    
    function video_inner_meta_box( $video ) {
    ?>
    <p>
      <label for="realizador">Youtube:</label>
      <br />
      <input type="text" name="yt_video" value="<?php echo get_post_meta( $video->ID, '_yt_video', true ); ?>" />
    </p>
    <p>
      <label for="realizador">Vimeo:</label>
      <br />
      <input type="text" name="Vimeo_video" value="<?php echo get_post_meta( $video->ID, '_Vimeo_video', true ); ?>" />
    </p>
    
    <?php
    }
    
    add_action( 'save_post', 'ewp_video_save_post', 10, 2 );
    
    function ewp_video_save_post( $video_id, $video ) {
    
       if ( ! $_POST['yt_video'] ) return;
    
       update_post_meta( $video_id, '_yt_video', strip_tags( $_POST['yt_video'] ) );
       update_post_meta( $video_id, '_Vimeo_video', strip_tags( $_POST['realizador_video'] ) );
    
       return true;
    
    }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Custom post type e metabox’ is closed to new replies.