Skip to main content
added 162 characters in body
Source Link
Valeka
  • 301
  • 3
  • 12

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

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);
    } else {
        return $link;
    }
}

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/'. $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);
Source Link
Valeka
  • 301
  • 3
  • 12

Changing custom post type URL issue

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);
    } else {
        return $link;
    }
}