Support » Fixing WordPress » Registering Taxonomies

  • Resolved scottiescotsman

    (@scottiescotsman)


    I have successfully added a custom post type and was adding some taxonomies.
    There are 3 questions relating to this post as I didn’t want to post 3 subjects regarding the same subject.
    #1 do I need to register all taxonomies individually / all together as I have 8.
    #2 can I add code to a taxonomy eg. img src=”test.png” so that it would output a picture, and if not how would I solve that issue.
    #3 how do I output the taxonomies.
    Here is a little code for you to view –

    function genres_taxonomy() {
    register_taxonomy(
    'genre',
    'movies',
    array(
    'hierarchical' => true,
    'label' => 'Genre',
    'query_var' => true,
    'rewrite' => array(
    'slug' => 'genre',
    'with_front' => false
    )
    )
    );
    }
    add_action(  'init', 'genres_taxonomy');
    
    function year_taxonomy() {
    register_taxonomy(
    'year',
    'movies',
    array(
    'hierarchical' => true,
    'label' => 'Year',
    'query_var' => true,
    'rewrite' => array(
    'slug' => 'year',
    'with_front' => false
    )
    )
    );
    }
    add_action(  'init', 'year_taxonomy');
    

    its for my movie collection .. that’s in the 1.000’s

    Hope you can help
    Steven

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi, you can just use the following code to generate the taxonomies for post type: “movie”

    <?php
    //Create Custom Taxonomy - Movie Category
    add_action( 'init', 'taxonomy_movie_category' );
    function taxonomy_movie_category(){
        $taxonomy_labels = array(
    		'name'              => __( 'Category' ),
    		'singular_name'     => __( 'Movie Category' ),
    		'search_items'      => __( 'Search Categories' ),
    		'all_items'         => __( 'All Movie Categories' ),
    		'parent_item'       => __( 'Parent Category' ),
    		'parent_item_colon' => __( 'Parent Category:' ),
    		'edit_item'         => __( 'Edit Category' ),
    		'update_item'       => __( 'Update Category' ),
    		'add_new_item'      => __( 'Add Moovie Category' ),
    		'new_item_name'     => __( 'New Movie Category Name' ),
    		'not_found'         => __( 'No Movie Categories Found.' ),
    		'menu_name'         => __( 'Movie Category' ),
        );
        $taxonomy_args = array(
                'hierarchical'      => true,
                'labels'            => $taxonomy_labels,
                'show_ui'           => true,
                'show_admin_column' => true,
                'query_var'         => true,
                'rewrite'           => array( 'slug' => 'movie_category' ),
        );
        register_taxonomy( 'movie_category', array( 'movie' ), $taxonomy_args );
    }
    ?>

    You can replace the words with any taxonomy that you wish to create.

    • This reply was modified 4 years, 1 month ago by Adarsh Verma.

    You can place this code in your active theme’s functions.php file or any custom plugin file.

    Hope this will help.

    smashing…. ok when yo go to your UI and go to movies & it shows you title, author date… how do I add some other options to there … such as duration of the movie.

    Thanks for your help
    Steven

    Hello @scottiescotsman
    To add additional details you should add meta boxes for custom post types you can see this plugin for the purpose.
    https://wordpress.org/plugins/meta-box/

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Registering Taxonomies’ is closed to new replies.