Problem:
The issue here is that the user's custom permalink structure was not working for one of his CPT.
The user's code was
add_filter( 'post_type_link', 'my_post_type_link2', 98, 2 ); function my_post_type_link2( $post_link, $post = null ) { if ( !empty($post) ) { $post_type = get_post_type($post->ID); if($post_type == "projects") { return str_replace('%post_id%', $post->ID, $post_link); } else { return str_replace('%post_id%', '', $post_link); } } } add_filter( 'post_type_link', 'type_link', 99, 2 ); function type_link( $post_link, $post = null ) { if ( !empty($post) ) { $post_type = get_post_type($post->ID); if($post_type == "projects1") { return str_replace('%post_id%', $post->ID, $post_link); } else { return str_replace('%post_id%', '', $post_link); } } }
Solution:
By right the user's code should've worked but it doesn't and I recommended that the functions be combined.
add_filter( 'post_type_link', 'my_post_type_link2', 99, 2 ); function my_post_type_link2( $post_link, $post = null ) { if ( !empty($post) ) { $post_type = get_post_type($post->ID); if($post_type == "projects" || $post_type == "projects1") { return str_replace('%post_id%', $post->ID, $post_link); } else { return str_replace('%post_id%', '', $post_link); } } }
Since the functions are exactly the same. Now just ensure that the $post_type slug is exactly the same as the one you had created in types.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | - |
- | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 14:00 – 18:00 | 13:00 – 18:00 | - |
Supporter timezone: America/Jamaica (GMT-05:00)
This topic contains 5 replies, has 2 voices.
Last updated by 6 years, 11 months ago.
Assisted by: Shane.