{"id":6233,"date":"2017-01-03T16:23:23","date_gmt":"2017-01-03T21:23:23","guid":{"rendered":"https:\/\/themespress.ca\/?p=6233"},"modified":"2022-09-04T08:07:45","modified_gmt":"2022-09-04T12:07:45","slug":"list-custom-posts-types-taxonomy","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/list-custom-posts-types-taxonomy\/","title":{"rendered":"List custom posts types taxonomy"},"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>For this tutorial, it&#8217;s important that your custom post type is configured with <strong><a href=\"https:\/\/codex.wordpress.org\/Function_Reference\/register_taxonomy\" target=\"_blank\" rel=\"noopener\">register_taxonomy<\/a><\/strong>. <\/p>\n<p>It&#8217;s a nice and easy way to list your custom post type&#8217;s categories. By default, we need to display post categories with wp_list_categories.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-5578617\" 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-5578617\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">&lt;?php wp_list_categories(); ?&gt;<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>Here&#8217;s an example of register_taxonomy and the taxonomy that needs to be recuperated. In this case it&#8217;s <strong>collaborateurs_cat<\/strong>.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-8843523\" 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-8843523\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">\/\/ Cat&eacute;gories custom post type\n\/* Voici donc la taxonomie *\/\nregister_taxonomy( &#039;collaborateurs_cat&#039;, \n\/* nom du custom post type *\/\narray(&#039;collaborateurs&#039;), \narray(\n\t&#039;hierarchical&#039;             =&gt; true,\n\t&#039;labels&#039;                         =&gt; array(\n\t&#039;name&#039;                           =&gt; __( &#039;Cat&eacute;gories&#039;, &#039;nom du theme&#039; ),\n\t&#039;singular_name&#039;                  =&gt; __( &#039;Cat&eacute;gories&#039;, &#039;nom du theme&#039; ),\n\t&#039;search_items&#039;                   =&gt; __( &#039;Rechercher une cat&eacute;gorie&#039;, &#039;nom du theme&#039; ),\n\t&#039;all_items&#039;                      =&gt; __( &#039;Toutes les cat&eacute;gories&#039;, &#039;nom du theme&#039; ),\n\t&#039;parent_item&#039;                    =&gt; __( &#039;Cat&eacute;gorie parente&#039;, &#039;nom du theme&#039; ),\n\t&#039;parent_item_colon&#039;              =&gt; __( &#039;Cat&eacute;gorie parente :&#039;, &#039;nom du theme&#039; ),\n\t&#039;edit_item&#039;                      =&gt; __( &#039;&Eacute;diter une cat&eacute;gorie&#039;, &#039;nom du theme&#039; ),\n\t&#039;update_item&#039;                    =&gt; __( &#039;Sauvegarder une cat&eacute;gorie&#039;, &#039;nom du theme&#039; ),\n\t&#039;add_new_item&#039;                   =&gt; __( &#039;Ajouter une cat&eacute;gorie&#039;, &#039;nom du theme&#039; ),\n\t&#039;new_item_name&#039;                  =&gt; __( &#039;Nouvelle cat&eacute;gorie&#039;, &#039;nom du theme&#039; )\n),\n    &#039;show_admin_column&#039;              =&gt; true,\n    &#039;show_ui&#039;                        =&gt; true,\n    &#039;query_var&#039;                      =&gt; true,\n    &#039;rewrite&#039;                        =&gt; array( &#039;slug&#039; =&gt; &#039;collaborateurs&#039; ),\n)\n);<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>You will need to customize it so it display the custom post type&#8217;s category taxonomy; the solution is to properly use its taxonomy. Here&#8217;s how to use get_terms.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-1895865\" 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-1895865\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">&lt;?php \n\/\/ R&eacute;cup&eacute;rer la taxonomie dans une variable \n$taxonomy = &#039;collaborateurs_cat&#039;; \n\/\/ Variable avec le get_terms \n$tax_terms = get_terms($taxonomy, array(&#039;hide_empty&#039; =&gt; false)); \n?&gt;<\/pre><\/div><\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"For this tutorial, it's important that your custom post type is configured with register_taxonomy. It's a nice and easy way to list your custom post type's categories. By default, we<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/list-custom-posts-types-taxonomy\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4582,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[357],"class_list":["post-6233","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-taxonomy"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6233","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=6233"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6233\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4582"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=6233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=6233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=6233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}