Taxonomies and show related

  • I’m going to create a music site using wordpress.
    In Music sites, we will have: Singers (who sing the song), Authors (who wrote the song), Category, and Albums.
    I have this (below code) to create taxonomies for Singers, Authors, Category,
    But the albums, how can i create the Albums so it can list as all albums, and it can show on Singer (single) page (list all albums of that singer).
    I tried to create 1 more taxonomy but it cannot display on singer page (dont know how to related it to singer page.

    Would you please me an ideas or example of code would be appreciate.

    function bt_taxonomies() {
    	$taxonomies = array(
    		array(
    			'slug'         => 'nhacsi',
    			'single_name'  => 'Author',
    			'plural_name'  => 'Authors',
    			'post_type'    => 'music',
    			'rewrite'      => array( 'slug' => 'nhacsi' ),
    		),
    		array(
    			'slug'         => 'casi',
    			'single_name'  => 'Singer',
    			'plural_name'  => 'Singers',
    			'post_type'    => 'music',
    			'rewrite'      => array( 'slug' => 'singer' ),
    		),
    		array(
    			'slug'         => 'theloai',
    			'single_name'  => 'Category',
    			'plural_name'  => 'Categories',
    			'post_type'    => 'music',
    			'rewrite'      => array( 'slug' => 'theloai' ),
    		),
    	);
    	foreach( $taxonomies as $taxonomy ) {
    		$labels = array(
    			'name' => $taxonomy['plural_name'],
    			'singular_name' => $taxonomy['single_name'],
    			'search_items' =>  'Search ' . $taxonomy['plural_name'],
    			'all_items' => 'All ' . $taxonomy['plural_name'],
    			'parent_item' => 'Parent ' . $taxonomy['single_name'],
    			'parent_item_colon' => 'Parent ' . $taxonomy['single_name'] . ':',
    			'edit_item' => 'Edit ' . $taxonomy['single_name'],
    			'update_item' => 'Update ' . $taxonomy['single_name'],
    			'add_new_item' => 'Add New ' . $taxonomy['single_name'],
    			'new_item_name' => 'New ' . $taxonomy['single_name'] . ' Name',
    			'menu_name' => $taxonomy['plural_name']
    		);
    
    		$rewrite = isset( $taxonomy['rewrite'] ) ? $taxonomy['rewrite'] : array( 'slug' => $taxonomy['slug'] );
    		$hierarchical = isset( $taxonomy['hierarchical'] ) ? $taxonomy['hierarchical'] : true;
    
    		register_taxonomy( $taxonomy['slug'], $taxonomy['post_type'], array(
    			'hierarchical' => $hierarchical,
    			'labels' => $labels,
    			'show_ui' => true,
    			'show_in_menu'       => true,
    			'query_var' => true,
    		'exclude_from_search' => false,
    			'rewrite' => $rewrite,
    		));
    	}
    
    }
    add_action( 'init', 'bt_taxonomies' );
  • Hi there,

    It sounds like you are creating a self hosted WordPress.org website and not one hosted on WordPress.com.

    This is the forum for WordPress.com.

    For help with WordPress.org websites please see here: 
    https://wordpress.org/support/

    To learn about the difference between the two please see here: 
    https://en.support.wordpress.com/com-vs-org/

    Hope it helps.

  • The topic ‘Taxonomies and show related’ is closed to new replies.