Title: Error when using wp_count_posts
Last modified: January 12, 2021

---

# Error when using wp_count_posts

 *  Resolved [Rasso Hilber](https://wordpress.org/support/users/nonverbla/)
 * (@nonverbla)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/error-when-using-wp_count_posts/)
 * Hi there!
 * After the update to 4.0 I encountered an error in my admin. I am using `wp_count_posts`,
   which leads to this error when your plugin is active:
 *     ```
       Notice: Trying to get property 'base' of non-object in wp-content/plugins/duplicate-post/src/ui/class-post-list.php on line 135
       ```
   
 * This is my code
 *     ```
       add_filter('add_menu_classes', 'my_add_menu_classes');
       /**
        * Show a 'pending'-batch for the post type 'music'
        *
        * @param Array $menu
        * @return Array
        */
       function my_add_menu_classes( $menu ) {
         if( !current_user_can('edit_others_posts') ) return $menu;
   
         foreach( $menu as $id => $item ) {
           if( $item[2] === 'edit.php?post_type=music' ) {
             $menu[$id][0] .= ' ' . get_pending_batch( 'music' );
           }    
         }
         return $menu;
       }
   
       /**
        * Create a 'pending' batch for a certain post type's count, just like in plugins
        *
        * @param string $post_type
        * @return string
        */
       function my_get_pending_batch( $post_type ) {
         $count_posts = wp_count_posts( $post_type ); // this causes issues with Duplicate Posts Version 4.0
         $counter = sprintf( '<span class="update-plugins count-%1$d"><span class="plugin-count" aria-hidden="true">%1$d</span><span class="screen-reader-text">%2$s</span></span>', $count_posts->pending, 'new drafts' );
         return $counter;
       }
       ```
   
    -  This topic was modified 5 years, 4 months ago by [Rasso Hilber](https://wordpress.org/support/users/nonverbla/).
    -  This topic was modified 5 years, 4 months ago by [Rasso Hilber](https://wordpress.org/support/users/nonverbla/).

Viewing 10 replies - 1 through 10 (of 10 total)

 *  Plugin Support [Maybellyne](https://wordpress.org/support/users/maybellyne/)
 * (@maybellyne)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/error-when-using-wp_count_posts/#post-13896613)
 * Hello,
 * We are sorry about the error.
 * Can you confirm that you are running WordPress 5.6? If yes, we would like to 
   rule out any plugin or theme conflicts that may occur. The fastest way to do 
   this is to **deactivate all non-Yoast plugins and switch to a standard theme**
   like [Twenty Nineteen](https://wordpress.org/themes/twentynineteen/). 
 * Test this on your development or staging site, if you have one. If not, we recommend
   using the [Health Check & Troubleshooting](https://wordpress.org/plugins/health-check/)
   plugin. This plugin allows you to run a conflict check **without affecting normal
   visitors to your site**.
 * As we can imagine that you’re unfamiliar with checking for conflicts, we’d like
   to point you to a step-by-step guide that will walk you through the process: 
   [How to check for plugin conflicts](https://kb.yoast.com/kb/how-to-check-for-plugin-conflicts/).
 *  Thread Starter [Rasso Hilber](https://wordpress.org/support/users/nonverbla/)
 * (@nonverbla)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/error-when-using-wp_count_posts/#post-13896700)
 * Thanks Maybellyne, I am a developer and I am sure that my issue lies somewhere
   inside Duplicate Post. I just switched to the standard theme twentynineteen, 
   deactivated all plugins except “Duplicate Post” and included my code in the functions.
   php of the default theme, with the post type ‘post’:
 *     ```
       add_filter('add_menu_classes', 'my_add_menu_classes');
       /**
        * Show a 'pending'-batch for the post type 'post'
        *
        * @param Array $menu
        * @return Array
        */
       function my_add_menu_classes( $menu ) {
         if( !current_user_can('edit_others_posts') ) return $menu;
   
         foreach( $menu as $id => $item ) {
           if( $item[2] === 'edit.php' ) {
             $menu[$id][0] .= ' ' . my_get_pending_batch( 'post' );
           }
         }
         return $menu;
       }
   
       /**
        * Create a 'pending' batch for a certain post type's count, just like in plugins
        *
        * @param string $post_type
        * @return string
        */
       function my_get_pending_batch( $post_type ) {
         $count_posts = wp_count_posts( $post_type );
         $counter = sprintf( '<span class="update-plugins count-%1$d"><span class="plugin-count" aria-hidden="true">%1$d</span><span class="screen-reader-text">%2$s</span></span>', $count_posts->pending, 'new drafts' );
         return $counter;
       }
       ```
   
 * Same error there.
    -  This reply was modified 5 years, 4 months ago by [Rasso Hilber](https://wordpress.org/support/users/nonverbla/).
 *  Plugin Support [Maybellyne](https://wordpress.org/support/users/maybellyne/)
 * (@maybellyne)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/error-when-using-wp_count_posts/#post-13896800)
 * Thanks for getting back. We are currently looking into the issue and a patch 
   will be released soon to fix this.
 * We appreciate your patience.
 *  [plerix](https://wordpress.org/support/users/plerix/)
 * (@plerix)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/error-when-using-wp_count_posts/#post-13897248)
 * Hi,
 * Same problem but with an admin impact.
    I also see : #0 /home/clch4709/public_html/
   wp-content/plugins/duplicate-post/src/ui/class-classic-editor.php(302): Yoast\
   WP\Duplicate_Post\Permissions_Helper->is_rewrite_and_republish_copy(false) #1/
   home/clch4709/public_html/wp-content/plugins/duplicate-post/src/ui/class-classic-
   editor.php(210): Yoast\WP\Duplicate_Post\UI\Classic_Editor->should_change_rewrite_republish_copy(
   false) #2 /home/clch4709/public_html/wp-includes/class-wp-hook.php(289): Yoast\
   WP\Duplicate_Post\UI\Classic_Editor->change_republish_strings_classic_editor(‘
   Une erreur crit…’, ‘There has been …’) #3 /home/clch4709/public_html/wp-includes/
   plugin.php(212): in /home/clch4709/public_html/wp-content/plugins/duplicate-post/
   src/class-permissions-helper.php on line 57 Using the Divi Theme (on a lot of
   sites) it blocks access to edit something in the Divi Library. Until the fix 
   I deactivate the duplicate post plugin.
 * Hopping a quick solution 😉
    Kind regards; Philippe
    -  This reply was modified 5 years, 4 months ago by [plerix](https://wordpress.org/support/users/plerix/).
 *  Plugin Support [Maybellyne](https://wordpress.org/support/users/maybellyne/)
 * (@maybellyne)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/error-when-using-wp_count_posts/#post-13897383)
 * [@plerix](https://wordpress.org/support/users/plerix/) We are currently looking
   into the issue and will communicate a resolution soon.
 *  [plerix](https://wordpress.org/support/users/plerix/)
 * (@plerix)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/error-when-using-wp_count_posts/#post-13897526)
 * Hi,
 * Wonderful and … so quick !!!
    4.0.1 tested and all works perfectly
 * Many thanks !
    Philippe
 *  [Taco Verdonschot](https://wordpress.org/support/users/tacoverdo/)
 * (@tacoverdo)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/error-when-using-wp_count_posts/#post-13898002)
 * Thanks for confirming [@plerix](https://wordpress.org/support/users/plerix/).
   Does it also resolve the issue for you, [@nonverbla](https://wordpress.org/support/users/nonverbla/)?
 *  Thread Starter [Rasso Hilber](https://wordpress.org/support/users/nonverbla/)
 * (@nonverbla)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/error-when-using-wp_count_posts/#post-13898144)
 * Yes, works with 4.0.1! Thanks.
    -  This reply was modified 5 years, 4 months ago by [Rasso Hilber](https://wordpress.org/support/users/nonverbla/).
 *  [Taco Verdonschot](https://wordpress.org/support/users/tacoverdo/)
 * (@tacoverdo)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/error-when-using-wp_count_posts/#post-13898150)
 * Thanks for the confirmation!
 *  Thread Starter [Rasso Hilber](https://wordpress.org/support/users/nonverbla/)
 * (@nonverbla)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/error-when-using-wp_count_posts/#post-13953026)
 * [@tacoverdo](https://wordpress.org/support/users/tacoverdo/) yes it does. Thank
   you!!

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Error when using wp_count_posts’ is closed to new replies.

 * ![](https://ps.w.org/duplicate-post/assets/icon-256x256.png?rev=2336666)
 * [Yoast Duplicate Post](https://wordpress.org/plugins/duplicate-post/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/duplicate-post/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/duplicate-post/)
 * [Active Topics](https://wordpress.org/support/plugin/duplicate-post/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/duplicate-post/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/duplicate-post/reviews/)

 * 10 replies
 * 4 participants
 * Last reply from: [Rasso Hilber](https://wordpress.org/support/users/nonverbla/)
 * Last activity: [5 years, 4 months ago](https://wordpress.org/support/topic/error-when-using-wp_count_posts/#post-13953026)
 * Status: resolved