Custom post URL 404 error

I have custom post type and custom taxonomy. Categories works well but posts give me 404. I dont know why. It worked before I define URL for hiearchical categories. Can anybody help me? Main fragments of code is below.

function produkty() {
$labels = array(…);
$args = array(
‘labels’ => $labels,
‘hierarchical’ => true,
‘rewrite’ => array( ‘hierarchical’ => true, ‘slug’ => ‘kategorie’, ‘with_front’ => false ),
‘public’ => true,
‘show_ui’ => true,
‘show_admin_column’ => true,
‘show_in_nav_menus’ => true,
‘show_tagcloud’ => true,
);
register_taxonomy(‘produkty’, array(‘podlahy’), $args);
}

add_action(‘init’, ‘produkty’, 0);

function podlahy() {

$labels = array(…);
$args = array(
‘label’ => __(‘Podlahy’, ‘idrevenepodlahy’),
‘description’ => __(‘Podlahy’, ‘idrevenepodlahy’),
‘labels’ => $labels,
‘supports’ => array(‘title’, ‘editor’, ‘thumbnail’,),
‘taxonomies’ => array(‘produkty’),
‘hierarchical’ => false,
‘public’ => true,
‘rewrite’ => array( ‘slug’ => ‘kategorie/%produkty%’, ‘with_front’ => true),
‘has_archive’ => ‘kategorie’,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘menu_position’ => 10,
‘menu_icon’ => ‘dashicons-screenoptions’,
‘show_in_admin_bar’ => true,
‘show_in_nav_menus’ => true,
‘can_export’ => true,
‘exclude_from_search’ => false,
‘publicly_queryable’ => true,
‘capability_type’ => ‘page’
);
register_post_type(‘podlahy’, $args);
}

add_action(‘init’, ‘podlahy’, 0);

function wpa_show_permalinks( $post_link, $post ){
if ( is_object( $post ) && $post->post_type == ‘podlahy’ ){
$terms = get_the_terms( $post->id , ‘produkty’);
$link = “”;
if( $terms ){
$parent = $terms[0]->term_id;
$parent2 = $terms[0]->parent;
$parent3 = 0;
$link = $terms[0]->slug;

if($parent2 > 0){
$terms = get_term( $parent2 );
$link = $terms->slug .”/”. $link;
$parent3 = $terms->parent;
}

if($parent3 > 0){
$terms = get_term( $parent3 );
$link = $terms->slug .”/”. $link;
}

return str_replace( ‘%produkty%’ , $link , $post_link );
}
}
return $post_link;
}
add_filter( ‘post_type_link’, ‘wpa_show_permalinks’, 1, 2 );

Read more here:: Custom post URL 404 error

Leave a Reply

Your email address will not be published. Required fields are marked *