1

I have created a custom taxonomy with the basic code below. I created a term called 'video' some time ago to test it. I created a few other terms today then noticed that I cannot delete or edit that first created term 'video'. It is grayed out and offers only the view link, which is a broken link. Oddly, using the correct permalink structure, the page for the 'video' term does display as expected.

I can create and edit other terms without any errors. There's also no errors anywhere else in the WP admin pages.

UPDATE:

After troubleshooting, I believe the issue is because I initially created the custom taxonomy with the name Purpose, but then changed it to purpose. Calling $object->taxonomy returns Purpose, while all the others listed in the admin panel return purpose.

How can I change this term's taxonomy from Purpose to purpose?

Here is the function that creates the taxonomy:

function post_purpose_taxonomy()
{
    $args = array (
        'labels' => array('name' => 'Purpose Tags', 'singular_name' => 'Purpose Tag'),
        'hierarchical' => false,
        'public' => true,
    );
    register_taxonomy('purpose', [ 'post', 'dvposts' ], $args);
}
add_action('init', 'post_purpose_taxonomy');

You can see that I register the taxonomy to both posts and the custom post type 'dvposts'.

Here is a snapshot:

Cannot delete or edit a single term in a custom taxonomy

10
  • This is unusual, but, I notice your register_taxonomy call is very small, normally there are a lot more options declared. I also notice that you make an extra call to register_taxonomy_for_object_type rather than just passing [ 'post', 'dvposts' ] as the second parameter. Have you disabled all plugins and confirmed that none of them cause this? Or that this still happens in a blank clean slate WP install with the default theme and that code?
    – Tom J Nowell
    Commented Jul 3, 2020 at 23:10
  • @TomJNowell This is a clean install and a custom theme from scratch. I'll try passing [ 'post', 'dvposts' ] in register_taxonomy instead and see what happens.
    – user38365
    Commented Jul 4, 2020 at 0:31
  • @TomJNowell Tried register_taxonomy('purpose', [ 'post', 'dvposts' ], $args); and removed register_taxonomy_for_object_type. That did not work. Also just tried passing 'capabilities' => array ('manage_terms','edit_terms','delete_terms','assign_terms') and no luck.
    – user38365
    Commented Jul 4, 2020 at 0:40
  • Activating the 2020 WP theme removes the custom taxonomy. Are you suggesting registering the custom taxonomy in the 2020 WP theme for testing?
    – user38365
    Commented Jul 4, 2020 at 0:46
  • 1
    Just keep iin mind that plugin won't fix your problem, I don't know the cause or the solution ot your issue, I'm just suggesting best practices and debugging techniques to try and help identify what's going on
    – Tom J Nowell
    Commented Jul 4, 2020 at 18:19

1 Answer 1

1

Credit for this answer goes entirely to CodeMascot: Create and move terms for taxonomies

After troubleshooting, I believe the issue is because I initially created the custom taxonomy with the name Purpose, but then changed it to purpose at another time. Calling $object->taxonomy returns Purpose on the affected term, while all the others listed in the admin panel return purpose.

I strongly suspect that the taxonomy originally starting with a capital letter created a privileges issue, probably related to some to-lower-case method because some privileges were allowed. Once the taxonomy names matched perfectly, all issues were resolved.

After my troubleshooting determined that the taxonomy key of the term was incorrect, the question then became "How to change an existing term's taxonomy key"? The answer is that you must access the powerful and risky global $wpdb. This variable allows you to access and write the WordPress database directly. I added the following to the functions.php file, then refreshed a page two or three times, and the issue was resolved.

function the_dramatist_change_terms_taxonomy( $term_id, $future_taxonomy ){
    global $wpdb;
    $update = $wpdb->update(
        $wpdb->prefix . 'term_taxonomy',
        [ 'taxonomy' => $future_taxonomy ],
        [ 'term_taxonomy_id' => $term_id ],
        [ '%s' ],
        [ '%d' ]
    );
    return $update;
}

the_dramatist_change_terms_taxonomy(26,'purpose');

Now that the change has been made, I have removed the function from the functions.php file and $object->taxonomy returns purpose.

3
  • 1
    You might want to adjust the answer as it doesn't make make sense on its own, a user coming across this won't understand what changing a terms taxonomy has to do with the grayed out term in the question
    – Tom J Nowell
    Commented Aug 12, 2020 at 23:08
  • @TomJNowell Better?
    – user38365
    Commented Aug 12, 2020 at 23:15
  • Better but best to move the extra bit added to the very top
    – Tom J Nowell
    Commented Aug 13, 2020 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.