/*
Theme Name: Impreza Child
Template: Impreza
Version: 1.0
Author:	UpSolution
Theme URI: http://impreza.us-themes.com/
Author URI: http://us-themes.com/
*/

/*Add your own styles here:*/

// Nadpisz rewrite dla taksonomii edycja
add_action('init', function() {
    // Zmień slug taksonomii
    global $wp_rewrite;
    
    // Nadpisz CPT lineup
    register_post_type('lineup', array_merge(
        get_post_type_object('lineup') ? 
            (array) get_post_type_object('lineup') : [],
        [
            'rewrite' => [
                'slug' => 'lineup/%edycja%',
                'with_front' => false,
            ]
        ]
    ));
}, 20);

// Filtr zamieniający %edycja% na prawdziwy slug
add_filter('post_type_link', function($link, $post) {
    if ($post->post_type !== 'lineup') return $link;
    
    $terms = get_the_terms($post->ID, 'edycja');
    if ($terms && !is_wp_error($terms)) {
        $link = str_replace('%edycja%', $terms[0]->slug, $link);
    } else {
        $link = str_replace('%edycja%/', '', $link);
    }
    
    return $link;
}, 10, 2);