WordPress的'post_type_link'隐藏永久链接

问题描述:

所以我只是通过WP-Types插件添加了一个自定义的发布类型,没有什么奇特的只是一个自定义的发布类型。现在,此自定义帖子类型的固定链接未显示出来。WordPress的'post_type_link'隐藏永久链接

我想通了,它有什么做的我(Woocommerce)产品的永久链接,此代码重写:

function append_id_string($link, $post) { 
    $post_meta = $post->ID; 
    if ('product' == get_post_type($post)) { 
     $link = $link . '#' .$post_meta; 
     return $link; 
    } 
} 

add_filter('post_type_link', 'append_id_string', 1, 2); 

删除这段代码的永久显示出来后。

为什么上面的代码也影响了我的自定义后类型以及如何使用此代码只影响我(Woocommerce)产品

这是我的猜测,但我认为你应该返还$link变量是否满足条件是否满足。像这样:

function append_id_string($link, $post) { 
    $post_meta = $post->ID; 
    if ('product' == get_post_type($post)) { 
     $link = $link . '#' .$post_meta; 
    } 
    return $link; 
} 

add_filter('post_type_link', 'append_id_string', 1, 2); 
+0

工作就像一个魅力!谢谢@Kodos –