I created a custom post type ‘products’ using ACF.
Then, I created the taxonomy ‘product categories’.
Now, when I click ‘view’ on one of these taxonomies like ‘t-shirts’,
I end up on this URL: ‘/product-category/t-shirts/’
I would like my URL to be: ‘/products/t-shirts/’
So, I tried going to the URL section of the taxonomy select ‘permalink rewrite’ and entered ‘products/’ in the URL slug.
Now, when I click ‘view’ on ‘t-shirts’, I end up on this URL: ‘/products/t-shirts/’, which is correct, but the page is a 404.
Am I missing a step?
Always go to the general WP settings > Permalinks and press Save, don’t do anything other than just press the save button
yes i just did that but the result is the same, after the changes if i go on the taxonomy page the url is correct but the page is a 404
i used this solution to solve that without using the ACF options:
function val_update_prodotto_rewrite_rules() {
$args = get_post_type_object(‘prodotto’);
$args->rewrite = array(
‘slug’ => ‘prodotti/%categoria-prodotto%’,
‘with_front’ => false
);
register_post_type(‘prodotto’, $args);
}
add_action(‘init’, ‘val_update_prodotto_rewrite_rules’);
function val_custom_post_type_permalink($post_link, $post) {
if (‘prodotto’ === $post->post_type) {
$terms = wp_get_object_terms($post->ID, ‘categoria-prodotto’);
if ($terms) {
return str_replace(‘%categoria-prodotto%’, $terms[0]->slug, $post_link);
}
}
return $post_link;
}
add_filter(‘post_type_link’, ‘val_custom_post_type_permalink’, 10, 2);
function val_update_categoria_prodotto_rewrite_rules() {
$args = get_taxonomy(‘categoria-prodotto’);
$args->rewrite = array(
‘slug’ => ‘prodotti’,
);
register_taxonomy(‘categoria-prodotto’, ‘prodotto’, $args);
}
add_action(‘init’, ‘val_update_categoria_prodotto_rewrite_rules’);