{"id":6190,"date":"2017-03-30T19:52:18","date_gmt":"2017-03-30T23:52:18","guid":{"rendered":"https:\/\/themespress.ca\/?p=6190"},"modified":"2022-09-03T11:41:54","modified_gmt":"2022-09-03T15:41:54","slug":"count-posts-specific-wordpress-taxonomy","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/count-posts-specific-wordpress-taxonomy\/","title":{"rendered":"Count posts in a specific WordPress 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><strong>Count posts in a specific WordPress taxonomy:<\/strong> This tutorial will show you how to create a query that will let you display the number of posts linked to a specific taxonomy slug.<\/p>\n<p>In our example below, our taxonomy is called video-cat\u00e9gorie that you need to force upon your arguments. We created a new category called <strong>En discoth\u00e8que<\/strong> with the en-discotheque slug (a category or taxonomy slug is the ID given when we create it).<\/p>\n<p>Here&#8217;s the code snippet to add into your single.php template:<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-2597614\" 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-2597614\" 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\/\/\/\/\/\/ Slug ou identifiant du non de la cat&eacute;gorie class&eacute;e dans votre taxonomie \/\/\/\/\/\n$catpagediscotheque = &#039;en-discotheque&#039;;\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ Requ&ecirc;te \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n$args = array(\n&#039;post_type&#039; =&gt; &#039;viavideos&#039;,\n&#039;post_status&#039; =&gt; &#039;published&#039;,\n\/\/\/ Ici on met notre taxonomy name \/\/\/\/\n&#039;video-categorie&#039; =&gt; $catpagediscotheque,\n&#039;numberposts&#039; =&gt; -1\n);\necho $num = count( get_posts( $args ) );\n?&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>You will get the number of posts linked to your taxonomy&#8217;s slug.<br \/>\n<a class=\"more\" href=\"https:\/\/codex.wordpress.org\/Taxonomies\" target=\"_blank\" rel=\"noopener noreferrer\">Understanding taxonomies<\/a><a class=\"more\" href=\"https:\/\/codex.wordpress.org\/Function_Reference\/register_taxonomy\" target=\"_blank\" rel=\"noopener noreferrer\">Save a taxonomy<\/a><\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"Count posts in a specific WordPress taxonomy: This tutorial will show you how to create a query that will let you display the number of posts linked to a specific<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/count-posts-specific-wordpress-taxonomy\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4626,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[357],"class_list":["post-6190","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\/6190","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=6190"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6190\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4626"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=6190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=6190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=6190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}