{"id":6256,"date":"2016-10-20T15:31:44","date_gmt":"2016-10-20T19:31:44","guid":{"rendered":"https:\/\/themespress.ca\/?p=6256"},"modified":"2022-09-06T19:24:35","modified_gmt":"2022-09-06T23:24:35","slug":"display-number-of-draft-posts","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/display-number-of-draft-posts\/","title":{"rendered":"Display the Number of Posts with Draft Status in Admin Menu"},"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>This tutorial will show you how to add a new function in your WordPress admin which will display the number of posts and post-type with a Draft status.<\/p>\n<p>This function will help WordPress admins to validate posts and post type pending verification with the Draft status.<\/p>\n<p>To accomplish this, we will use the <strong><a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/add_menu_classes\/\" target=\"_blank\" rel=\"noopener\">add_menu_classes<\/a><\/strong> filter.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading\" >Display the Number of Posts with Draft Status in Admin Menu<\/h2><div id=\"ts-enlighterjs-container-4970123\" 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-4970123\" 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=\"\">add_filter( &#039;add_menu_classes&#039;, &#039;viavideos_pending_number&#039;); \nfunction viavideos_pending_number( $menu ) {\n    \/\/ Changer par le nom de votre Post Type ou post\n\t$type = &#039;viavideos&#039;;\n    \/\/ Vous pouvez ici mettre un autre statut\n\t$status = &#039;draft&#039;;\n\t\/\/ On fait le compte des Posts Ou Post Type\n    $num_posts = wp_count_posts( $type, &#039;readable&#039; );\n\t\/\/ On part de 0 en statut draft et on fait le compte\n    $pending_count = 0;\n    if ( !empty($num_posts-&amp;gt;$status) )\n        $pending_count = $num_posts-&amp;gt;$status;\n\n    \/\/ build string to match in $menu array\n    if ($type == &#039;post&#039;) {\n        $menu_str = &#039;edit.php&#039;;\n    \/\/ support custom post types\n    } else {\n        $menu_str = &#039;edit.php?post_type=&#039; . $type;\n    }\n\n    \/\/ On affiche le resultat dans le menu admin concern&eacute;\n    foreach( $menu as $menu_key =&amp;gt; $menu_data ) {\n        if( $menu_str != $menu_data[2] )\n            continue;\n        $menu[$menu_key][0] .= &quot; &lt;span class=&quot;update-plugins count-$pending_count&quot;&gt;&lt;span class=&quot;plugin-count&quot;&gt;&quot; . number_format_i18n($pending_count) . &#039;&lt;\/span&gt;&lt;\/span&gt;&#039;;\n    }\n    return $menu;\n}<\/pre><\/div><\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"This tutorial will show you how to add a new function in your WordPress admin which will display the number of posts and post-type with a Draft status. This function<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/display-number-of-draft-posts\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4547,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[318,330,326],"class_list":["post-6256","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-functions","tag-posts","tag-users"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6256","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=6256"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6256\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4547"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=6256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=6256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=6256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}