Mostrare termini di tassonomia vuoti con get_terms()

11 set 2014, 14:14:47
Visualizzazioni: 16.2K
Voti: 3

Ho una funzione impostata come segue:

<?php $terms = get_terms("wpsc_product_category");
 if ( !empty( $terms ) && !is_wp_error( $terms ) ){
     foreach ( $terms as $term ) { ?>
        <li class="calendar-filter-menu-item" data-filter=".<?php echo $term->slug; ?>"><?php echo $term->count; ?></li>
    <?php }
 } ?>   

Che mostra lo slug e il count per ogni tassonomia, l'unico problema è che non mostra le tassonomie che non hanno post assegnati, vengono visualizzate solo quelle con post assegnati. È possibile mostrare anche le tassonomie vuote?

0
Tutte le risposte alla domanda 2
0

Puoi utilizzare l'argomento hide_empty di get_terms(). Il suo valore predefinito è impostato su true.

Fallo in questo modo:

$args = array(
    'hide_empty' => false
);
$terms = get_terms( 'wpsc_product_category', $args );
11 set 2014 14:27:38
0

Se stai utilizzando la modalità di richiesta stringa, usa "0" invece di "false":

$terms = get_terms('hide_empty=0');
22 ott 2019 01:19:46