Custom column into custom taxonomy (img tag with slug-name as file name)
-
11-04-2021 - |
Pergunta
How to add $term->name (slug) into custom column cells as the file name?
$columns = '<img src="SLUG_NAME.jpg">';
function custom_column_header( $columns ){
$columns['image'] = 'Image';
return $columns;
}
add_filter( "manage_edit-genre_columns", 'custom_column_header', 10);
function custom_column_content( $value, $column_name, $term_id ){
if ($column_name === 'image') {
$columns = '<img src="SLUG_NAME.jpg">';
}
return $columns;
}
add_action( "manage_genre_custom_column", 'custom_column_content', 10, 3);
Solução
You can use get_term_field()
like this:
if ($column_name === 'image') {
$slug = get_term_field( 'slug', $term_id );
$columns = '<img src="' . $slug . '.jpg">';
}
Or get_term()
:
if ($column_name === 'image') {
$term = get_term( $term_id );
$columns = '<img src="' . $term->slug . '.jpg">';
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a wordpress.stackexchange