Skip to content

Instantly share code, notes, and snippets.

@tevashov
Last active October 27, 2022 21:57
Show Gist options
  • Select an option

  • Save tevashov/5172449 to your computer and use it in GitHub Desktop.

Select an option

Save tevashov/5172449 to your computer and use it in GitHub Desktop.
Add custom post type with taxonomy #WP
function post_type_albums() {
register_post_type(
'albums',
array( 'label' => __('Albums'),
'public' => true,
'show_ui' => true,
'supports' => array('post-thumbnails', 'excerpts', 'trackbacks', 'comments')
)
);
// Custom Taxonomy for Genres: categories specific for this post type
register_taxonomy( 'genres', 'albums', array( 'hierarchical' => true, 'label' => __('Genres') ) );
// Custom Taxonomy for Performer: add tags specific for this post type.
register_taxonomy(
'performer', 'albums',
array('hierarchical' => false,
'label' => __('Performer'),
'query_var' => 'performer',
'rewrite' => array('slug' => 'performer')
)
);
}
add_action('init', 'post_type_albums');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment