{"id":4396838,"date":"2013-12-10T10:33:11","date_gmt":"2013-12-10T10:33:11","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/changing-sample-permalink\/"},"modified":"2016-08-21T13:21:43","modified_gmt":"2016-08-21T13:21:43","slug":"changing-sample-permalink","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/changing-sample-permalink\/","title":{"rendered":"Changing sample permalink"},"content":{"rendered":"<p>Hello all,<\/p>\n<p>I have made myself a custom rewrite for a post type I&#8217;ve made. All &#8216;s well and all &#8216;s fine, but I run into a slight problem.<\/p>\n<p>When the post is auto saved, the permalink structure does not show correctly in the sample permalink under the title.<\/p>\n<p>It shows as http:\/\/loc.test-site.org\/?post_type=matches&amp;p=137 where with my code I expect it to be: http:\/\/loc.test-site.org\/match\/%d%\/%m%\/%Y%\/%post-name%\/<\/p>\n<p>If I save the post, it all works fine, but when it autosaves it&#8217;s not.<\/p>\n<p>Anyone have any idea how I can fix this?<\/p>\n<p>I use the code below to generate my new permalink<\/p>\n<pre><code>function better_match_permalinks( $permalink, $post ) {\n\tglobal $wp_rewrite;\n\n\t$timestamp = get_field( &#039;match_datetime&#039;, $post-&gt;ID );\n\n\t$structure = __( &#039;match&#039;, &#039;apollo&#039; );\n\tif( ! empty( $timestamp ) ) {\n\t\t$structure .= date( &#039;\/d\/m\/Y&#039;, $timestamp );\n\t} else {\n\t\t$structure .= date( &#039;\/d\/m\/Y&#039;, strtotime( $post-&gt;post_date ) );\n\t}\n\t$structure .= &#039;\/%matches%\/&#039;;\n\t$wp_rewrite-&gt;add_rewrite_tag( &quot;%matches%&quot;, &#039;([^\/]+)&#039;, &quot;matches=&quot; );\n\t$wp_rewrite-&gt;add_permastruct( &#039;matches&#039;, $structure, false );\n\n\treturn $permalink;\n}<\/code><\/pre>\n<p>I hope some one can help me out.<\/p>\n<p>Thanks<\/p>\n<p>Mark<\/p>\n","protected":false},"template":"","class_list":["post-4396838","topic","type-topic","status-closed","hentry","topic-tag-autosave","topic-tag-custom-post-type","topic-tag-permalink","topic-tag-sample"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/4396838","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/4396838\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=4396838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}