'Wordpress 'post_type_link' hides permalink
So I just added a custom post type through the WP-Types plugin, nothing fancy just a custom post type. Now the permalink of this custom post type isn't showing up.
I figured out that it had something to do with the rewriting of my (Woocommerce) products permalinks with this code:
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 );
After removing this piece of code the permalink shows up.
Why is the above code also affecting my custom post type and how can I use this code to only affect my (Woocommerce) products
Solution 1:[1]
This is my guess but I think you should return the $link
variable whether the condition is met or not. Like this:
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 );
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Cave Johnson |