Home › Forums › General Issues › ACF taxonomy and url rewrite
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’);
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.