Home › Forums › General Issues › ACF taxonomy and url rewrite › Reply To: ACF taxonomy and url rewrite
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’);
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.