Advertisement
Wordpress

Showing Users Post Counts by Custom Post Type in the Admin’s User List

When i do my project to develop wordpress become interactive website, like all people can register and upload their artwork and content. I get some problem in user list. The first, i create post type “artwork”, but when i enter to user page, this page cannot showing the post count by artist post type. It’s just show, count from post (default wordpress post type). To slove this problem, i search in my fovorite search engine, yup that is google and i get some solution like bellow,

Showing Users Post Counts

Showing Users Post Counts by Custom Post Type in the Admin's User List

<br />
function custom_column_user_count_list($output = '', $column_name, $user_id) {<br />
 global $wpdb;</p>
<p>if( $column_name !== 'your_post_type_name' )<br />
 return;</p>
<p>$where = get_posts_by_author_sql( 'your_post_type_name', true, $user_id );<br />
 $result = $wpdb-&gt;get_var( &quot;SELECT COUNT(*) FROM $wpdb-&gt;posts $where&quot; );</p>
<p>return '&lt;a href=&quot;' . admin_url(&quot;edit.php?post_type=your_post_type_name&amp;author=$user_id&quot;) . '&quot; title=&quot;Post Type Count&quot;&gt;' . $result . '&lt;/a&gt;';<br />
}<br />
add_filter('manage_users_custom_column', 'custom_column_user_count_list', 10, 3);</p>
<p>function users_columns($columns) {<br />
 $columns['your_post_type_name'] = __( 'Your Post Type Name Bar', 'textdomain' );</p>
<p>return $columns;<br />
}<br />
add_filter('manage_users_columns', 'users_columns');<br />

That code mybe help you to¬†showing users post counts by custom post type in the admin’s user list.

Thanks to sorich87 for this tutorial

Editorial Team

Editorial Team adalah mereka yang menulis artikel untuk blog PinDexain.

Related Stories

Leave a Reply

Your email address will not be published. Required fields are marked *