{"id":13896553,"date":"2021-01-12T11:34:11","date_gmt":"2021-01-12T11:34:11","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/error-when-using-wp_count_posts\/"},"modified":"2021-01-12T11:35:24","modified_gmt":"2021-01-12T11:35:24","slug":"error-when-using-wp_count_posts","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/error-when-using-wp_count_posts\/","title":{"rendered":"Error when using wp_count_posts"},"content":{"rendered":"<p>Hi there! <\/p>\n<p>After the update to 4.0 I encountered an error in my admin. I am using <code>wp_count_posts<\/code>, which leads to this error when your plugin is active:<\/p>\n<pre><code>\nNotice: Trying to get property &#039;base&#039; of non-object in wp-content\/plugins\/duplicate-post\/src\/ui\/class-post-list.php on line 135\n<\/code><\/pre>\n<p>This is my code<\/p>\n<pre><code> \nadd_filter(&#039;add_menu_classes&#039;, &#039;my_add_menu_classes&#039;);\n\/**\n * Show a &#039;pending&#039;-batch for the post type &#039;music&#039;\n *\n * @param Array $menu\n * @return Array\n *\/\nfunction my_add_menu_classes( $menu ) {\n  if( !current_user_can(&#039;edit_others_posts&#039;) ) return $menu;\n  \n  foreach( $menu as $id =&gt; $item ) {\n    if( $item[2] === &#039;edit.php?post_type=music&#039; ) {\n      $menu[$id][0] .= &#039; &#039; . get_pending_batch( &#039;music&#039; );\n    }    \n  }\n  return $menu;\n}\n\n\/**\n * Create a &#039;pending&#039; batch for a certain post type&#039;s count, just like in plugins\n *\n * @param string $post_type\n * @return string\n *\/\nfunction my_get_pending_batch( $post_type ) {\n  $count_posts = wp_count_posts( $post_type ); \/\/ this causes issues with Duplicate Posts Version 4.0\n  $counter = sprintf( &#039;&lt;span class=&quot;update-plugins count-%1$d&quot;&gt;&lt;span class=&quot;plugin-count&quot; aria-hidden=&quot;true&quot;&gt;%1$d&lt;\/span&gt;&lt;span class=&quot;screen-reader-text&quot;&gt;%2$s&lt;\/span&gt;&lt;\/span&gt;&#039;, $count_posts-&gt;pending, &#039;new drafts&#039; );\n  return $counter;\n}\n<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-13896553","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13896553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":2,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13896553\/revisions"}],"predecessor-version":[{"id":13896558,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13896553\/revisions\/13896558"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=13896553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}