Changing sample permalink
-
Hello all,
I have made myself a custom rewrite for a post type I’ve made. All ‘s well and all ‘s fine, but I run into a slight problem.
When the post is auto saved, the permalink structure does not show correctly in the sample permalink under the title.
It shows as https://loc.test-site.org/?post_type=matches&p=137 where with my code I expect it to be: https://loc.test-site.org/match/%d%/%m%/%Y%/%post-name%/
If I save the post, it all works fine, but when it autosaves it’s not.
Anyone have any idea how I can fix this?
I use the code below to generate my new permalink
function better_match_permalinks( $permalink, $post ) { global $wp_rewrite; $timestamp = get_field( 'match_datetime', $post->ID ); $structure = __( 'match', 'apollo' ); if( ! empty( $timestamp ) ) { $structure .= date( '/d/m/Y', $timestamp ); } else { $structure .= date( '/d/m/Y', strtotime( $post->post_date ) ); } $structure .= '/%matches%/'; $wp_rewrite->add_rewrite_tag( "%matches%", '([^/]+)', "matches=" ); $wp_rewrite->add_permastruct( 'matches', $structure, false ); return $permalink; }
I hope some one can help me out.
Thanks
Mark
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Changing sample permalink’ is closed to new replies.