Support » Plugin: Custom Post Type UI » Unable to unassign custom taxonomies on a custome post type

  • Resolved Boldair Développement

    (@boldairdeveloppement)


    Hi,

    I’m using CPT UI 1.8.1.

    However I created custom types and taxonomies about a year ago for a site here are their codes :

    function cptui_register_my_cpts() {
    
    	/**
    	 * Post Type: Cibles de campagne.
    	 */
    
    	$labels = [
    		"name" => __( "Cibles de campagne", "custom-post-type-ui" ),
    		"singular_name" => __( "Cible de campagne", "custom-post-type-ui" ),
    		"menu_name" => __( "Mes Cibles de campagne", "custom-post-type-ui" ),
    		"all_items" => __( "Toutes les Cibles de campagne", "custom-post-type-ui" ),
    		"add_new" => __( "Ajouter un nouveau", "custom-post-type-ui" ),
    		"add_new_item" => __( "Ajouter une nouvelle Cible de campagne", "custom-post-type-ui" ),
    		"edit_item" => __( "Modifier Cible de campagne", "custom-post-type-ui" ),
    		"new_item" => __( "Nouvelle Cible de campagne", "custom-post-type-ui" ),
    		"view_item" => __( "Afficher la Cible de campagne", "custom-post-type-ui" ),
    		"view_items" => __( "Afficher les Cibles de campagne", "custom-post-type-ui" ),
    		"search_items" => __( "Recherche de Cibles de campagne", "custom-post-type-ui" ),
    		"not_found" => __( "Aucun résultat pour Cibles de campagne", "custom-post-type-ui" ),
    		"not_found_in_trash" => __( "Aucune Cibles de campagne trouvé dans la corbeille", "custom-post-type-ui" ),
    		"parent" => __( "Parent Cible de campagne :", "custom-post-type-ui" ),
    		"featured_image" => __( "Image mise en avant pour cette Cible de campagne", "custom-post-type-ui" ),
    		"set_featured_image" => __( "Définir l’image mise en avant pour cette Cible de campagne", "custom-post-type-ui" ),
    		"remove_featured_image" => __( "Retirer l’image mise en avant pour cette Cible de campagne", "custom-post-type-ui" ),
    		"use_featured_image" => __( "Utiliser comme image mise en avant pour cette Cible de campagne", "custom-post-type-ui" ),
    		"archives" => __( "Archives de Cible de campagne", "custom-post-type-ui" ),
    		"insert_into_item" => __( "Insérer dans Cible de campagne", "custom-post-type-ui" ),
    		"uploaded_to_this_item" => __( "Téléverser sur ce Cible de campagne", "custom-post-type-ui" ),
    		"filter_items_list" => __( "Filtrer la liste de Cibles de campagne", "custom-post-type-ui" ),
    		"items_list_navigation" => __( "Navigation de liste de Cibles de campagne", "custom-post-type-ui" ),
    		"items_list" => __( "Liste de Cibles de campagne", "custom-post-type-ui" ),
    		"attributes" => __( "Attributs de Cibles de campagne", "custom-post-type-ui" ),
    		"name_admin_bar" => __( "Cible de campagne", "custom-post-type-ui" ),
    		"item_published" => __( "Cible de campagne publié", "custom-post-type-ui" ),
    		"item_published_privately" => __( "Cible de campagne publié en privé.", "custom-post-type-ui" ),
    		"item_reverted_to_draft" => __( "Cible de campagne repassés en brouillon.", "custom-post-type-ui" ),
    		"item_scheduled" => __( "Cible de campagne planifié", "custom-post-type-ui" ),
    		"item_updated" => __( "Cible de campagne mis à jour.", "custom-post-type-ui" ),
    		"parent_item_colon" => __( "Parent Cible de campagne :", "custom-post-type-ui" ),
    	];
    
    	$args = [
    		"label" => __( "Cibles de campagne", "custom-post-type-ui" ),
    		"labels" => $labels,
    		"description" => "",
    		"public" => true,
    		"publicly_queryable" => true,
    		"show_ui" => true,
    		"show_in_rest" => true,
    		"rest_base" => "",
    		"rest_controller_class" => "WP_REST_Posts_Controller",
    		"has_archive" => false,
    		"show_in_menu" => true,
    		"show_in_nav_menus" => true,
    		"delete_with_user" => false,
    		"exclude_from_search" => false,
    		"capability_type" => "post",
    		"map_meta_cap" => true,
    		"hierarchical" => false,
    		"rewrite" => [ "slug" => "cibles_de_campagnes", "with_front" => true ],
    		"query_var" => true,
    		"supports" => [ "title", "editor", "thumbnail" ],
    	];
    
    	register_post_type( "cibles_de_campagnes", $args );
    
    	/**
    	 * Post Type: Campagnes.
    	 */
    
    	$labels = [
    		"name" => __( "Campagnes", "custom-post-type-ui" ),
    		"singular_name" => __( "Campagne", "custom-post-type-ui" ),
    		"menu_name" => __( "Mes Campagnes", "custom-post-type-ui" ),
    		"all_items" => __( "Toutes les Campagnes", "custom-post-type-ui" ),
    		"add_new" => __( "Ajouter une nouvelle", "custom-post-type-ui" ),
    		"add_new_item" => __( "Ajouter une nouvelle Campagne", "custom-post-type-ui" ),
    		"edit_item" => __( "Modifier Campagne", "custom-post-type-ui" ),
    		"new_item" => __( "Nouvelle Campagne", "custom-post-type-ui" ),
    		"view_item" => __( "Afficher la Campagne", "custom-post-type-ui" ),
    		"view_items" => __( "Afficher les Campagnes", "custom-post-type-ui" ),
    		"search_items" => __( "Recherche de Campagnes", "custom-post-type-ui" ),
    		"not_found" => __( "Aucun résultat pour Campagnes", "custom-post-type-ui" ),
    		"not_found_in_trash" => __( "Aucune Campagnes trouvée dans la corbeille", "custom-post-type-ui" ),
    		"parent" => __( "Parent Campagne :", "custom-post-type-ui" ),
    		"featured_image" => __( "Image mise en avant pour cette Campagne", "custom-post-type-ui" ),
    		"set_featured_image" => __( "Définir l’image mise en avant pour cette Campagne", "custom-post-type-ui" ),
    		"remove_featured_image" => __( "Retirer l’image mise en avant pour cette Campagne", "custom-post-type-ui" ),
    		"use_featured_image" => __( "Utiliser comme image mise en avant pour cette Campagne", "custom-post-type-ui" ),
    		"archives" => __( "Archives de Campagne", "custom-post-type-ui" ),
    		"insert_into_item" => __( "Insérer dans Campagne", "custom-post-type-ui" ),
    		"uploaded_to_this_item" => __( "Téléverser sur cette Campagne", "custom-post-type-ui" ),
    		"filter_items_list" => __( "Filtrer la liste de Campagnes", "custom-post-type-ui" ),
    		"items_list_navigation" => __( "Navigation de liste de Campagnes", "custom-post-type-ui" ),
    		"items_list" => __( "Liste des Campagnes", "custom-post-type-ui" ),
    		"attributes" => __( "Attributs de Campagnes", "custom-post-type-ui" ),
    		"name_admin_bar" => __( "Campagne", "custom-post-type-ui" ),
    		"item_published" => __( "Campagne publiée", "custom-post-type-ui" ),
    		"item_published_privately" => __( "Campagne publiée en privé.", "custom-post-type-ui" ),
    		"item_reverted_to_draft" => __( "Campagne repassée en brouillon.", "custom-post-type-ui" ),
    		"item_scheduled" => __( "Campagne planifiée", "custom-post-type-ui" ),
    		"item_updated" => __( "Campagne mise à jour.", "custom-post-type-ui" ),
    		"parent_item_colon" => __( "Parent Campagne :", "custom-post-type-ui" ),
    	];
    
    	$args = [
    		"label" => __( "Campagnes", "custom-post-type-ui" ),
    		"labels" => $labels,
    		"description" => "",
    		"public" => true,
    		"publicly_queryable" => true,
    		"show_ui" => true,
    		"show_in_rest" => true,
    		"rest_base" => "",
    		"rest_controller_class" => "WP_REST_Posts_Controller",
    		"has_archive" => false,
    		"show_in_menu" => true,
    		"show_in_nav_menus" => true,
    		"delete_with_user" => false,
    		"exclude_from_search" => false,
    		"capability_type" => "post",
    		"map_meta_cap" => true,
    		"hierarchical" => false,
    		"rewrite" => [ "slug" => "campagnes", "with_front" => true ],
    		"query_var" => true,
    		"menu_icon" => "dashicons-megaphone",
    		"supports" => [ "title", "editor", "thumbnail", "excerpt", "page-attributes" ],
    		"taxonomies" => [ "groupe_de_campagnes" ],
    	];
    
    	register_post_type( "campagnes", $args );
    }
    
    add_action( 'init', 'cptui_register_my_cpts' );
    
    function cptui_register_my_taxes_categorie_cibles() {
    
    	/**
    	 * Taxonomy: Catégories cibles.
    	 */
    
    	$labels = [
    		"name" => __( "Catégories cibles", "custom-post-type-ui" ),
    		"singular_name" => __( "Catégorie cibles", "custom-post-type-ui" ),
    		"menu_name" => __( "Catégories cibles", "custom-post-type-ui" ),
    		"all_items" => __( "Toutes les Catégories cibles", "custom-post-type-ui" ),
    		"edit_item" => __( "Modifier Catégorie cibles", "custom-post-type-ui" ),
    		"view_item" => __( "Afficher Catégorie cibles", "custom-post-type-ui" ),
    		"update_item" => __( "Mettre à jour le nom de Catégorie cibles", "custom-post-type-ui" ),
    		"add_new_item" => __( "Ajouter une nouvelle Catégorie cibles", "custom-post-type-ui" ),
    		"new_item_name" => __( "Nom de la nouvelle Catégorie cibles", "custom-post-type-ui" ),
    		"parent_item" => __( "Parent de Catégorie cibles", "custom-post-type-ui" ),
    		"parent_item_colon" => __( "Parent Catégorie cibles :", "custom-post-type-ui" ),
    		"search_items" => __( "Recherche de Catégories cibles", "custom-post-type-ui" ),
    		"popular_items" => __( "Catégories cibles populaires", "custom-post-type-ui" ),
    		"separate_items_with_commas" => __( "Séparer Catégories cibles avec des virgules", "custom-post-type-ui" ),
    		"add_or_remove_items" => __( "Ajouter ou supprimer Catégories cibles", "custom-post-type-ui" ),
    		"choose_from_most_used" => __( "Choisir parmi les Catégories cibles les plus utilisées", "custom-post-type-ui" ),
    		"not_found" => __( "Aucun résultat pour Catégories cibles", "custom-post-type-ui" ),
    		"no_terms" => __( "Aucune Catégories cibles", "custom-post-type-ui" ),
    		"items_list_navigation" => __( "Navigation de liste de Catégories cibles", "custom-post-type-ui" ),
    		"items_list" => __( "Liste de Catégories cibles", "custom-post-type-ui" ),
    	];
    
    	$args = [
    		"label" => __( "Catégories cibles", "custom-post-type-ui" ),
    		"labels" => $labels,
    		"public" => true,
    		"publicly_queryable" => true,
    		"hierarchical" => true,
    		"show_ui" => true,
    		"show_in_menu" => true,
    		"show_in_nav_menus" => true,
    		"query_var" => true,
    		"rewrite" => [ 'slug' => 'categorie_cibles', 'with_front' => true, ],
    		"show_admin_column" => true,
    		"show_in_rest" => true,
    		"rest_base" => "categorie_cibles",
    		"rest_controller_class" => "WP_REST_Terms_Controller",
    		"show_in_quick_edit" => true,
    			];
    	register_taxonomy( "categorie_cibles", [ "cibles_de_campagnes" ], $args );
    }
    add_action( 'init', 'cptui_register_my_taxes_categorie_cibles' );
    
    

    As you can see I’m using the taxonomy ‘Groupes de campagnes’ (Campaigns groups) conjointly with the two post types : ‘Cibles de campagnes’ (Campaign targets) , and ‘Campagnes’ (campaign). The goal being to associate the Campain targets with a Campaign though a taxonomy (a target becoming a campaign target if it has the same taxonomy as the campaign).

    And it used to work without a hitch.

    However, in recent times, WP Updated, CPT Updated too.. I couldn’t rightly tell you exactly when it started to go awry (from which version of WP or which of CPT UI, as the site is programmed to auto update and a few versions went by before I needed to launch a new campaign (the site if made for an NGO lobbying members of the European Parliament on environmental issues, so they launch a new campaign every few months)).

    The thing is that now, when editing one ‘Cibles de campagnes’ post I cannot uncheck an assign taxonomy ‘Groupe de campagnes’, even worse, when assigning individually a taxonomy in this post type, it does not assign the right one and randomly adds one or several others

    I can use some PHP to reset the metadata and remove those taxonomies, but for my client its a bit of an ordeal,

    Strangely enough, if I assign the taxonomies with a grouped modification (check the post on on the posts list page, and change via Bulk action), it does work properly ( However Bulk actions does not allow to remove a taxonomy, so I’m still stuck with that)

    It should also be noted that in the other post type ‘Campagnes’ with which the taxonomy ‘Groupes de campagnes’ is shared, I can assign and unassign items from the taxonomy ‘Groupes de campagnes’ normally through the metabox. The problem is happening only with the ‘Cibles de Campagnes’ post type.

    You guys are pretty much the go to when it comes to custom post types, so you may have and idea of what has gone wrong, even though I’m not entirely sure it relates directly with CPT UI itself (other than the problems in in the relation between custom post types and custom post taxonomies, even though any help would be appreciated. Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    Wish I had some ideas for what’s going on here but I sadly don’t. We don’t enforce anything with this type of thing, so it’s hard to say it’s coming from CPTUI at all.

    Not sure if you have a dev site that you can tinker with where this is also happening, because I’m wondering if there’s a conflict with a different plugin or so going on that may be enforcing the things you’re experiencing above.

    Thread Starter Boldair Développement

    (@boldairdeveloppement)

    Hi,
    Well I hadn’t my hopes up on that one, but you never now, you could have had the perfect reply in the style of ‘Oh of course I’ve seen this before and this is why it’s happening:’

    And yes I have a dev site, and yes it’s probably some conflict, at some level, the thing is debugging that is not going to be a fun ride.

    Anyhow thanks for your reply, it at least helps to eliminate CPT UI as the cause 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Unable to unassign custom taxonomies on a custome post type’ is closed to new replies.