• Resolved wpforever18

    (@wpforever18)


    Hello! My site has several authors who publish posts only on “Custom Types” that I created. They do not publish in the standard “Posts”. In the Users panel option correctly appears all authors registered in WordPress, but in the column “Posts” appears 0, because there only displays the number of posts published in type “Post”, which is not my case. I’ve tried to find functions to modify this and haven’t found it. Does anyone know how to change this default for WordPress to display the number of user posts independent of the Custom Type used by it? Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Thread Starter wpforever18

    (@wpforever18)

    Thank you, Steve! The code of the page you indicated works, but I found a simpler and more functional code. For those who need it:

    function wpbr_86681_manage_users_columns( $columns ) {
    	// Remove a coluna padr?o do WordPress.
    	unset( $columns['posts'] );
    	// Insere uma nova.
    	$columns['custom_posts_count'] = __( 'Posts' );
    	return $columns;
    }
    add_filter( 'manage_users_columns', 'wpbr_86681_manage_users_columns' );
    
    /**
     * Popula o valor da nova coluna
     *
     * @param string $value       Valor da célula até agora.
     * @param string $column_name Nome da coluna.
     * @param int    $user_id     ID do usuário.
     * @return string             Valor final da célula.
     */
    function wpbr_86681_manage_users_custom_column( $value, $column_name, $user_id ) {
    	if ( 'custom_posts_count' === $column_name ) {
    		$total_count = 0;
    		// Lista com os CPTs que devem ser contados. Altere para os slugs do SEU CPT.
    		$custom_post_types = [ 'slug_cpt_1', 'slug_cpt_2', 'slug_cpt_3' ];
    		foreach ( $custom_post_types as $cpt ) {
    			$cpt_count    = count_many_users_posts( [ $user_id ], $cpt );
    			$total_count += $cpt_count[ $user_id ];
    		}
    		return $total_count;
    	}
    	return $value;
    }
    add_action( 'manage_users_custom_column', 'wpbr_86681_manage_users_custom_column', 10, 3 );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Number of posts created in Custom Type’ is closed to new replies.