{"id":13519039,"date":"2020-10-11T12:21:48","date_gmt":"2020-10-11T12:21:48","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/when-i-modify-the-products-permalink-the-pages-stop-working\/"},"modified":"2020-10-11T12:21:48","modified_gmt":"2020-10-11T12:21:48","slug":"when-i-modify-the-products-permalink-the-pages-stop-working","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/when-i-modify-the-products-permalink-the-pages-stop-working\/","title":{"rendered":"When I modify the product&#8217;s permalink, the pages stop working"},"content":{"rendered":"<p>I&#8217;m trying to modify the Woocommerce slugs with the object <code>$wp_rewrite<\/code>. When I modify it, everything works as I put it, but the rest as the pages stop working. Here the code:<\/p>\n<pre><code>public function rewrite(): void {\n        global $wp_rewrite;\n\n        $wp_rewrite-&gt;add_rewrite_tag(&quot;%category%&quot;, &#039;([^\/]+)&#039;, &quot;category=&quot;)\n        $wp_rewrite-&gt;add_permastruct( &#039;category&#039;, &#039;%category%&#039; );\n        $wp_rewrite-&gt;add_rewrite_tag(&quot;%product_cat%&quot;, &#039;([^\/]+)&#039;, &quot;product_cat=&quot;);\n        $wp_rewrite-&gt;add_permastruct( &#039;product_cat&#039;, &#039;%product_cat%&#039; );\n        $wp_rewrite-&gt;add_rewrite_tag(&quot;%product%&quot;, &#039;([^\/]+)&#039;, &quot;product=&quot;);\n        $wp_rewrite-&gt;add_permastruct( &#039;product&#039;, &#039;%product_cat%\/%product%&#039; );\n    \n}<\/code><\/pre>\n<p>This function is executed with the <code>hook init<\/code>.<\/p>\n<p>Does anyone know why it doesn&#8217;t work or is it a <strong>bug<\/strong>?<\/p>\n<p>I also tried modifying the array of <code>extra_permastructs<\/code>, but it doesn&#8217;t work either.<\/p>\n","protected":false},"template":"","class_list":["post-13519039","topic","type-topic","status-publish","hentry","topic-tag-permalinks","topic-tag-permastruct"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13519039","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\/13519039\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=13519039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}