Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Mark Jansen on "Changing sample permalink"

$
0
0

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 http://loc.test-site.org/?post_type=matches&p=137 where with my code I expect it to be: http://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 all articles
Browse latest Browse all 8245

Trending Articles