Question

Is it possible to add a number to the body class according to how many custom posts a current user has published, e.g. CUSTOMPOST-4

Was it helpful?

Solution

add to functions.php

function wpc_body_class_section($classes) {  
    if (is_user_logged_in()) {        
        $classes[] = 'CUSTOMPOST-'.count_user_posts(get_current_user_id());
    } 

    return $classes;  
}  
add_filter('body_class','wpc_body_class_section');  

OTHER TIPS

You can use count_user_posts

See:

https://developer.wordpress.org/reference/functions/count_user_posts/

Edit:

<?php
    if (is_user_logged_in()) {
       $count_class = 'CUSTOMPOST-'.count_user_posts(get_current_user_id());
    }
?>
<body <?php body_class($count_class); ?>> 

Something like this in your header

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top