My recommendation is to structure the array so that your variations become “regular rows”.
I would use your implementation of prepare_items
for that.
Here your array is changed to something like that:
$this->items = array(
array(
'id' => 2,
'page' => 'page2',
'url' => 'page2',
'alt-id' => null,
'alt-title' => null
),
array(
'id' => null,
'page' => null,
'url' => null,
'alt-id' => 2,
'alt-title' => 'alternate-title-2'
),
array(
'id' => null,
'page' => null,
'url' => null,
'alt-id' => 3,
'alt-title' => 'alternate-title-3'
)
);
Then I would define custom functions for all columns by using column_$custom( $item )
(docs: https://developer.wordpress.org/reference/classes/wp_list_table/).
Something like that:
function column_id($item){
return is_null($item['id']) ? '' : intval($item['id']);
}
function column_page($item){
return is_null($item['page']) ? '' : esc_html($item['page']);
}
function column_url($item){
return is_null($item['url']) ? '' : esc_html($item['url']);
}
function column_alt_id($item){
return is_null($item['alt-id']) ? '' : intval($item['alt-id']);
}
function column_alt_title($item){
return is_null($item['alternate-title-3']) ? '' : esc_html($item['alternate-title-3']);
}
I assume you have already defined your columns with get_columns
like that (or similar):
function get_columns() {
return array(
'id' => 'ID',
'page' => 'Page',
'url' => 'URL',
'alt_id' => 'Alternative ID',
'alt_title' => 'Alternative Title',
);
}
This is key because your WP_List_Table subclass needs to know that you want to call your custom column methods (e.g. column_alt_title
as shown above).