I have this function and it does just what I need, it replace words in URL perfectly, but links don't work. All links are good and display on site well structured, as I wanted, but just don't open posts. Is there any way that I can make it work?
add_filter('post_type_link', 'replace_link', 1, 3);
function replace_link( $link, $post = 0 ){
if ( $post->post_type == 'item' ){
return home_url('food/'. $name$post->ID);
} else {
return $link;
}
}
function custom_rewrite_rule() {
add_rewrite_rule('^food/([^/]*)/?','?item=$matches[1]','top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);