Custom rewrite rule based on other custom post type title
-
Hi,
Can you help me out with this problem?
I want to rewrite custom post type – mieszkania, so they have url like so:/inwestycja/176-kamienica/19009/ (where number is mieszkanie’s ID).
So what i got is that code in register post for mieszkanie.
'rewrite' => array( 'with_front' => false, 'slug' => '/inwestycja/%mieszkanie_slug%' )
and this code for dynamic url change. But it doesn’t work with your plugin. (it works in native WP with post_type_link)
Any idea why ?
//Rewrite rule function change_apartment_url( $url, $post ) { if ( 'mieszkanie' == get_post_type( $post ) ) { $inwestycja = get_field('inwestycja', $post-ID); $inwestycjaObj = get_post($inwestycja); //$inwest_slug = 'lofthaus-zablocie'; $inwest_slug = $inwestycjaObj->post_name; return str_replace('%mieszkanie_slug%', $inwest_slug, $url); } return $url; } add_filter( 'permalink_manager_filter_permastructure', 'change_apartment_url', 5, 2 );
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
- The topic ‘Custom rewrite rule based on other custom post type title’ is closed to new replies.