admin管理员组文章数量:1317915
I import my custom terms from a desktop program using MySQL queries. But all the terms lead me to a 404 page. I tried flushing rewrites many times, it didn't help. It only helps when I save individual terms at https://[mysite]/wp-admin/term.php?taxonomy=store-category&tag_ID=[int ID]
I create my custom taxonomy like this
$labels = some labels
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => false,
'rewrite' => true
);
register_taxonomy( 'store-category', array( 'tdlrm_store_item' ), $args );
Then I insert my terms into my database:
//repeated for each term
//insert term into wp_terms
$wpdb->insert($wpdb->prefix.'terms', array(
'name' => $import_group['name'],
'slug' => $import_group['slug']
));
//get the inserted term id
$term_id = $wpdb->insert_id;
//insert the term's id from my program
$wpdb->insert($wpdb->prefix.'termmeta',array(
'term_id' => $term_id,
'meta_key' => 'import_id',
'meta_value' => $import_group['id']
));
//connect to taxonomy: store-category
$wpdb->insert($wpdb->prefix.'term_taxonomy',array(
'term_taxonomy_id' => $term_id,
'term_id' => $term_id,
'taxonomy' => 'store-category',
'parent' => 0 //I have another function that inserts child items
));
That's it. I've got a term in wp_terms
, it's connected to taxonomy in wp_term_taxonomy
.
Then, each product has its $import_group['id'], I just look for it in meta_value in wp_termmeta
and insert the returned term_id as the term_taxonomy_id in wp_terms_relationships
.
Looks like I've got everything covered, but when I go to [site root]/store-category/[term-slug]/, it leads me to a 404 page. What am I doing wrong? Is there any other place I have to insert term related data to? wp_options?
Flushing rewrite rules does not help (tried many times). Also, the number of posts shown under each of the terms is 0 (wrong), maybe this is related. Also, when I go to a term's wp-admin page and save it, this fixes the 404 issue for this term. But I can't do it manually, too many terms.
I've read this, this and similar questions but all the answers seem to be variants of 'try to flush rewrites again', which I did.
Oh, and I've just noticed. The same happens with individual posts: 404 until I refresh their term.
I tried deleting data from rewrite_rules in wp_options too, no use.
I changed 'rewrite' => true to 'rewrite' => false, and I don't get 404 page now, but still no idea how to fix the issue with rewrite turned on.
All irrelevant plugins are deactivated
I import my custom terms from a desktop program using MySQL queries. But all the terms lead me to a 404 page. I tried flushing rewrites many times, it didn't help. It only helps when I save individual terms at https://[mysite]/wp-admin/term.php?taxonomy=store-category&tag_ID=[int ID]
I create my custom taxonomy like this
$labels = some labels
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => false,
'rewrite' => true
);
register_taxonomy( 'store-category', array( 'tdlrm_store_item' ), $args );
Then I insert my terms into my database:
//repeated for each term
//insert term into wp_terms
$wpdb->insert($wpdb->prefix.'terms', array(
'name' => $import_group['name'],
'slug' => $import_group['slug']
));
//get the inserted term id
$term_id = $wpdb->insert_id;
//insert the term's id from my program
$wpdb->insert($wpdb->prefix.'termmeta',array(
'term_id' => $term_id,
'meta_key' => 'import_id',
'meta_value' => $import_group['id']
));
//connect to taxonomy: store-category
$wpdb->insert($wpdb->prefix.'term_taxonomy',array(
'term_taxonomy_id' => $term_id,
'term_id' => $term_id,
'taxonomy' => 'store-category',
'parent' => 0 //I have another function that inserts child items
));
That's it. I've got a term in wp_terms
, it's connected to taxonomy in wp_term_taxonomy
.
Then, each product has its $import_group['id'], I just look for it in meta_value in wp_termmeta
and insert the returned term_id as the term_taxonomy_id in wp_terms_relationships
.
Looks like I've got everything covered, but when I go to [site root]/store-category/[term-slug]/, it leads me to a 404 page. What am I doing wrong? Is there any other place I have to insert term related data to? wp_options?
Flushing rewrite rules does not help (tried many times). Also, the number of posts shown under each of the terms is 0 (wrong), maybe this is related. Also, when I go to a term's wp-admin page and save it, this fixes the 404 issue for this term. But I can't do it manually, too many terms.
I've read this, this and similar questions but all the answers seem to be variants of 'try to flush rewrites again', which I did.
Oh, and I've just noticed. The same happens with individual posts: 404 until I refresh their term.
I tried deleting data from rewrite_rules in wp_options too, no use.
I changed 'rewrite' => true to 'rewrite' => false, and I don't get 404 page now, but still no idea how to fix the issue with rewrite turned on.
All irrelevant plugins are deactivated
Share Improve this question edited Oct 31, 2020 at 16:14 Artem asked Oct 31, 2020 at 13:40 ArtemArtem 3152 silver badges13 bronze badges 6 | Show 1 more comment1 Answer
Reset to default 0EUREKA!
My taxonomy name is 'store-category'. When i used 'rewrite' = true or 'rewrite' = array('slug' => 'category') it was giving me a 404 error. When I changed it to 'rewrite' => array('slug' => 'group') the problem just went away!
So, the problem turned out to be a rewrite conflict. WordPress had been looking for my store-categories within categories, hence the 404 error.
No idea how 'store-category' fits in (when rewrite is just set true), but obviously it caused the same problem.
So, SOLUTION: don't use slugs that match default WP slugs; try changing your slug to something else.
本文标签: permalinksMySQLinserted custom taxonomy term lead to 404flush rewrites doesn39t help
版权声明:本文标题:permalinks - MySQL-inserted custom taxonomy term lead to 404, flush rewrites doesn't help 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742023783a2415166.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
wp_insert_term()
andadd_term_meta()
? – Sally CJ Commented Oct 31, 2020 at 14:59