Support » Developing with WordPress » Insert custom taxonomy into category queries

  • I created a plugin that creates a custom post (the-house) and a custom taxonomy (house_category).

    Everything works fine except that in the theme locations and the admin where you have categories query, only the categories created in “category” are shown. I wanted to list house_category categories without having to make changes to the theme. How can I do this?

    function the_house_category(){
    
    		$labels = array(
    			'name'                  => _( 'House Categories'),
    			'singular_name'         => _( 'House Category'),
    			);
    
    		$args = array(
    			'labels'            => $labels,
    			'public'            => true,
    			'show_in_nav_menus' => true,
    			'show_admin_column' => false,
    			'hierarchical'      => true,
    			'show_tagcloud'     => true,
    			'show_ui'           => true,
    			'query_var'         => true,
    			'rewrite'           => array('slug'=> 'house'),
    			'query_var'         => true,
    			'capabilities'      => array(),
    			);
    
    		register_taxonomy( 'house_category', 'the-house', $args );
    	}
    	add_action('init', 'the_house_category');
    	
    	
    	
    	
    	
    	function posts_house(){
    
    		$labels = array(
    			'name'               => __( 'House Posts'),
    			'singular_name'      => __( 'House Post')
    			);
    
    		$args = array(
    			'labels'              => $labels,
    			'hierarchical'        => false,
    			'description'         => 'description',
    			'taxonomies'          => array('house_category'),
    			'public'              => true,
    			'show_ui'             => true,
    			'show_in_menu'        => true,
    			'show_in_admin_bar'   => true,
    			'menu_position'       => 4,
    			'menu_icon'           => 'dashicons-admin-home',
    			'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',
    			'supports'            => array(
    				'title',
    				'editor',
    				'thumbnail',
    				'custom-fields',
    				'comments',
    				'revisions',
    				'post-formats',
    				),
    			);
    
    		register_post_type( 'the-house', $args );
    
    	}
    	add_action( 'init', 'posts_house' );
Viewing 3 replies - 1 through 3 (of 3 total)
  • Joy

    (@joyously)

    Taxonomies are per post type, and a lot of the admin is also.
    If you want a shared taxonomy, you will have to register it differently, or try to filter all the places that categories are used.

    atrevid0

    (@atrevid0)

    Could you tell me where I can see how I do this ??? Just to make it clear if I explained well what I want.

    These categories(https://imgur.com/a/e44d9AO) were made using the “category” I wanted to be listed in all my categories created with “house_category” without editing the theme

    Moderator bcworkz

    (@bcworkz)

    On the edit screen for the-house posts, there should already be a meta box for house_category terms. If you don’t see it, try using the screen’s “Screen Options” tab and be sure the House Categories item is checkmarked. You can also hide the category meta box here if you so desire. These are per user settings, other users can manage what they see in a similar manner.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.