Support

Account

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’);