是否有任何方法根据自定义post类型管理表中的post数据添加自定义css类?

发布于 2022-09-17 11:45:39
终于找到解决办法了。成立于WordPress文档
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;
}https://wordpress.stackexchange.com/questions/409570
复制相似问题