Is there any way to add a custom css class based on post data in the custom post type admin table?
1 Answer
Finally got a solution. Founded in WordPress Documentation
add_filter('post_class', 'set_row_post_class', 10,3);
function set_row_post_class($classes, $class, $post_id){
if (!is_admin()) { //make sure we are in the dashboard
return $classes;
}
$screen = get_current_screen(); //verify which page we're on
if ('my-custom-type' != $screen->post_type && 'edit' != $screen->base) {
return $classes;
}
//check if some meta field is set
$profile_incomplete = get_post_meta($post_id, 'profile_incomplete', true);
if ('yes' == $profile_incomplete) {
$classes[] = 'profile_incomplete'; //add a custom class to highlight this row in the table
}
// Return the array
return $classes;
}
-
I think it should be
if ('my-custom-type' != $screen->post_type || 'edit' != $screen->base) {
(||
instead of&&
) Jan 20 at 8:16