Eu uso esta função para obter e exibir todas as tags de cada produto:
public function get_product_tags_list() {
global $product;
if ( ! is_a( $product, 'WC_Product' ) ) {
return;
}
$separator = '<span class="separator">, </span></li><li>';
$before = '<ul><li>';
$after = '</li></ul>';
return get_the_term_list( $product->get_id(), 'product_tag', $before, $separator, $after );
}
como posso ordenar a lista de minhas tags em ordem decrescente?
Saudações
A única maneira de permitir a alteração opções de ordenação é construir a sua própria função baseado em WordPress get_the_term_list()
código fonte função central, substituindo a função get_the_terms()
pela wp_get_post_terms()
qual permite que os parâmetros adicionais para alterar o WP_Term_Query
como segue:
public function get_product_tags_list() {
global $product;
if ( ! is_a( $product, 'WC_Product' ) ) {
return;
}
$taxonomy = 'product_tag'; // The taxonomy
$args = array( // Your sorting parameters below
'orderby' => 'slug',
'order' => 'DESC',
);
$terms = wp_get_post_terms( $product->get_id(), $taxonomy, $args );
if ( is_wp_error( $terms ) ) {
return $terms;
}
if ( empty( $terms ) ) {
return false;
}
$links = array();
foreach ( $terms as $term ) {
$link = get_term_link( $term, $taxonomy );
if ( is_wp_error( $link ) ) {
return $link;
}
$links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
}
$term_links = apply_filters( "term_links-{$taxonomy}", $links ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
$separator = '<span class="separator">, </span></li><li>';
$before = '<ul><li>';
$after = '</li></ul>';
return $before . join( $separator, $term_links ) . $after;
}
O código entra no arquivo functions.php do tema filho ativo (ou tema ativo). Deve funcionar.
Documentação:
Este artigo é coletado da Internet.
Se houver alguma infração, entre em [email protected] Delete.
deixe-me dizer algumas palavras