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:
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:
Share Improve this question edited Aug 12, 2020 at 21:35 user38365 asked Jul 3, 2020 at 22:14 user38365user38365 2841 gold badge4 silver badges18 bronze badges 10 | Show 5 more comments1 Answer
Reset to default 1Credit 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
.
register_taxonomy
call is very small, normally there are a lot more options declared. I also notice that you make an extra call toregister_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[ 'post', 'dvposts' ]
inregister_taxonomy
instead and see what happens. – user38365 Commented Jul 4, 2020 at 0:31register_taxonomy('purpose', [ 'post', 'dvposts' ], $args);
and removedregister_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