J'utilise get_the_term_list et manage_posts_custom_column pour afficher les termes d'une coutume taxonomie dans la liste des publications personnalisées, dans l'administrateur WordPress.
add_action( 'manage_mycustompost_posts_custom_column' , 'custom_mycustompost_column', 10, 2 );
function custom_mycustompost_column( $column, $post_id ) {
switch ( $column ) {
case 'category_names':
echo get_the_term_list( $post_id , 'mycustomcategory' , '' , ',' , '' );
break;
}
}
Cependant, pour chaque terme de taxonomie, je reçois un lien vers la page publique qui affiche les messages pour ce terme: http://www.myblog.com/mycustomcategory/test/
Je voudrais obtenir un lien qui filtre la liste dans l'administrateur WordPress. Je voudrais un lien comme: http://www.myblog.com/wp-admin/edit.php?post_type=post&category_name=news
Le type de lien que je reçois dans la liste des messages, pour les balises ou les catégories des messages WordPress par défaut.
Y at-il une fonction WordPress qui fait ça?
Il ne l’a pas intégré à une fonction que vous pouvez utiliser, mais ce qui suit fonctionnera:
$taxonomy = 'my-taxonomy';
$taxonomy_object = get_taxonomy( $taxonomy );
$object_type = get_post_type($post_id);
if ( $terms = get_the_terms( $post_id, $taxonomy ) ) {
$out = array();
foreach ( $terms as $t ) {
$posts_in_term_qv = array();
$posts_in_term_qv['post_type'] = $object_type;
if ( $taxonomy_object->query_var ) {
$posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
} else {
$posts_in_term_qv['taxonomy'] = $taxonomy;
$posts_in_term_qv['term'] = $t->slug;
}
$out[] = sprintf( '<a href="%s">%s</a>',
esc_url( add_query_arg( $posts_in_term_qv, 'edit.php' ) ),
esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
);
}
/* translators: used between list items, there is a space after the comma */
echo join( __( ', ' ), $out );
};