{"id":6401,"date":"2016-02-08T15:22:39","date_gmt":"2016-02-08T20:22:39","guid":{"rendered":"https:\/\/themespress.ca\/?p=6401"},"modified":"2022-09-11T15:51:10","modified_gmt":"2022-09-11T19:51:10","slug":"display-a-custom-post-types-categories","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/display-a-custom-post-types-categories\/","title":{"rendered":"Display a Custom Post Type&#8217;s Categories"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>Simply create a new Post Type and a <strong>taxonomy<\/strong> for your new Custom Post Type.<\/p>\n<p>Once the taxonomy is set and your post type posts are published, here&#8217;s the query to use (in our example, we want the Region taxonomy): <\/p>\n<p>This query can be used with the archive-region.php or taxonomy.php templates<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading\" >Display a Custom Post Type's Categories<\/h2><div id=\"ts-enlighterjs-container-7441347\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-7441347\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">&lt;?php \n$taxonomy = &#039;region&#039;; \/\/ get the term IDs assigned to post. \n$post_terms = wp_get_object_terms( $post-&gt;ID, $taxonomy, array( &#039;fields&#039; =&gt; &#039;ids&#039; ) );\n\/\/ separator between links\n$separator = &#039;, &#039;;\nif ( !empty( $post_terms ) &amp;&amp; !is_wp_error( $post_terms ) ) {\n$term_ids = implode( &#039;,&#039; , $post_terms );\n$terms = wp_list_categories( \n\t&#039;title_li&#039; =&gt; &#039;&#039;,\n\t&#039;style&#039;    =&gt; &#039;none&#039;,\n\t&#039;echo&#039;     =&gt; false,\n\t&#039;taxonomy&#039; =&gt; $taxonomy,\n\t&#039;include&#039;  =&gt; $term_ids\n);\n$terms = rtrim( trim( str_replace( &#039;&lt;br \/&gt;&#039;,  $separator, $terms ) ), $separator );\n\/\/ display post categories\necho  &#039;R&eacute;gion : &#039;  . $terms;\n}\n?&gt;<\/pre><\/div><\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"Simply create a new Post Type and a taxonomy for your new Custom Post Type. Once the taxonomy is set and your post type posts are published, here's the query<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/display-a-custom-post-types-categories\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4494,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[318,357],"class_list":["post-6401","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-functions","tag-taxonomy"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/comments?post=6401"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6401\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4494"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=6401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=6401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=6401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}