{"id":513,"date":"2017-06-13T17:04:16","date_gmt":"2017-06-13T22:04:16","guid":{"rendered":"http:\/\/www.marcblase.com\/blog\/?p=513"},"modified":"2017-10-19T10:59:50","modified_gmt":"2017-10-19T15:59:50","slug":"custom-taxonomy-and-custom-post-type-rewrites","status":"publish","type":"post","link":"https:\/\/ma.rcbla.se\/blog\/2017\/06\/custom-taxonomy-and-custom-post-type-rewrites\/","title":{"rendered":"Custom Taxonomy and Custom Post Type Rewrites"},"content":{"rendered":"<p>When creating Custom Taxonomies and Custom Post types with rewrite rules in WordPress, the order in which they are registered matters. With the taxonomy registered first, WordPress will be able to work it&#8217;s magic for the rewrite rules to work.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\/\/ TAXONOMY FIRST\r\n$tax_args = array(\r\n    'labels'  =&gt; 'TAX_NAME',\r\n    'rewrite' =&gt; array( 'slug' =&gt; 'CPT\/TAX\/' )\r\n);\r\nregister_taxonomy( 'CUSTOM_TAX_TYPE', 'CUSTOM_POST_TYPE', $tax_args );\r\n\r\n\/\/ POST TYPE SECOND\r\n$cpt_args =  array(\r\n    'labels'  =&gt; 'CPT_NAME',\r\n    'rewrite  =&gt; ' array( 'slug' =&gt; 'CPT' )\r\n);\r\nregister_post_type( 'CUSTOM_POST_TYPE', $cpt_args );\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>When creating Custom Taxonomies and Custom Post types with rewrite rules in WordPress, the order in which they are registered matters. With the taxonomy registered first, WordPress will be able to work it&#8217;s magic for the rewrite rules to work. \/\/ TAXONOMY FIRST $tax_args = array( &#8216;labels&#8217; =&gt; &#8216;TAX_NAME&#8217;, &#8216;rewrite&#8217; =&gt; array( &#8216;slug&#8217; =&gt; &#8216;CPT\/TAX\/&#8217; [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-513","post","type-post","status-publish","format-standard","hentry","category-coding"],"_links":{"self":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/513","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/comments?post=513"}],"version-history":[{"count":5,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/513\/revisions"}],"predecessor-version":[{"id":518,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/513\/revisions\/518"}],"wp:attachment":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/media?parent=513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/categories?post=513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/tags?post=513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}