• I’m using a single taxonomy across two custom post types.
    The taxonomy registers, the custom posts display correctly from the front end.

    I have two Custom Post Types:
    1. Member Directory
    2. Directory Image

    One Taxonomy:
    1. Type of Service

    Here’s what happens:

    1. Add an entry to Member Directory, assign a ‘type of service’ to that entry.
    2. Add an entry to Directory Image, assign a ‘type of service’ to that entry.
    3. Go back to member directory and edit the entry (added in Step 1). Whilst the url shows the correct Post ID in query vars, the entry displayed is the Directory Image added in Step 2.
    4. If I uncheck the ‘type of service’ in Directory Image, I can edit the Member Directory entry without issue.

    Everything else seems to work correctly.

    The code I’m using:

    add_action( 'init', 'register_memberprofile_taxonomy', 0 );
    function register_memberprofile_taxonomy()
    {
      $labels = array(
        'name' => _x( 'Type Of Service', 'taxonomy general name' ),
        'singular_name' => _x( 'Type Of Service', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Type Of Service' ),
        'all_items' => __( 'All Type Of Services' ),
        'parent_item' => __( 'Parent Type Of Service' ),
        'parent_item_colon' => __( 'Parent Type Of Service:' ),
        'edit_item' => __( 'Edit Type Of Service' ),
        'update_item' => __( 'Update Type Of Service' ),
        'add_new_item' => __( 'Add New Type Of Service' ),
        'new_item_name' => __( 'New Type Of Service Name' ),
        'menu_name' => __( 'Type Of Service' ),
      ); 	
    
      register_taxonomy('type-of-service','', array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'type-of-service' ),
      ));
    }
    
    /* Adding the Custom Post Type for Members Directory */
    
    add_action('init', 'add_memberdirectory');
    function add_memberdirectory()
    {
      $labels = array(
        'name' => _x('Member Directory', 'post type general name'),
        'singular_name' => _x('Member Directory', 'post type singular name'),
        'add_new' => _x('Add New', 'infobox'),
        'add_new_item' => __('Add New Member Profile'),
        'edit_item' => __('Edit Member Profile'),
        'new_item' => __('New Member Profile'),
        'view_item' => __('View Member Profile'),
        'search_items' => __('Search Member Profiles'),
        'not_found' =>  __('No Member Profiles found'),
        'not_found_in_trash' => __('No Member Profiles found in Trash'),
        'parent_item_colon' => ''
      );
      $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        '_builtin' => false, // It's a custom post type, not built in!
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => true,
        'rewrite' => array("slug" => "memberdirectory"), // Permalinks format
        'taxonomies' => array('type-of-service'),
        'menu_position' => 5,
        'supports' => array('title','editor','author','thumbnail'/*,'custom-fields'/*,'excerpt','comments'*/)
      );
      register_post_type('memberdirectory',$args);
    
      $labels2 = array(
        'name' => _x('Directory Image', 'post type general name'),
        'singular_name' => _x('Directory Image', 'post type singular name'),
        'add_new' => _x('Add New', 'infobox'),
        'add_new_item' => __('Add New Directory Image'),
        'edit_item' => __('Edit Directory Image'),
        'new_item' => __('New Directory Image'),
        'view_item' => __('View Directory Image'),
        'search_items' => __('Search Directory Image'),
        'not_found' =>  __('No Directory Images found'),
        'not_found_in_trash' => __('No Directory Images found in Trash'),
        'parent_item_colon' => ''
      );
      $args2 = array(
        'labels' => $labels2,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        '_builtin' => false, // It's a custom post type, not built in!
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => true,
        'rewrite' => array("slug" => "directoryimage"), // Permalinks format
    	'taxonomies' => array('type-of-service'),
        'menu_position' => 6,
        'supports' => array('title','editor',/*'author',*/'thumbnail'/*,'custom-fields','excerpt','comments'*/)
      );
      register_post_type('directoryimage',$args2);
    }

    Whislt I could create a separate Taxonomy for the Directory Image, it seems a waste as the “categories” will be exactly the same.

    Any insights?

  • The topic ‘Single Taxonomy, Multi Post Types, Can't edit custom post entry’ is closed to new replies.