2017-10-04 3 views
0

La liste suivante répertorie tous les termes, puis-je obtenir de l'aide pour la réviser afin qu'elle affiche tous les termes à l'exception de la page active/actuelle? Je vous remercie.Afficher tous les termes excluant la page en cours

$terms = get_terms('topics', array( 
'orderby' => 'name', 
'order' => 'ASC', 
)); 
if (! empty($terms)){ 
    foreach ($terms as $term) { 
     $term_thumb = get_field('image', $term); 
     echo '<li><a href="'.esc_url(get_term_link($term->term_id)) .'"><img src="' .$term_thumb['url']. '"><span class="model">'.$term->name .'</span></a></li>'; 
    } 
} 

Répondre

0

Vous pouvez faire quelque chose comme ceci:

// create an empty array holder 
    $current_tax_ids = array(); 

    // get the post terms 
    $current_tax = get_the_terms($post->ID, 'topics'); 

    // creating loop to insert ids 
    foreach($current_tax as $tax) { 
     $current_tax_ids[] = $tax->term_id; 
    } 

    $args = array(
     'taxonomy' => 'topics', 
     'hide_empty' => 0, 
     'exclude' => $current_tax_ids // exclude the terms 
    ); 

    // get all the terms 
    $all_terms = get_terms($args); 
    // now do whatever you want 

donc si vous suivez mes commentaires il devrait être clair, mais au fond, vous voulez obtenir les conditions de poste actuel et stocker l'id dans un tableau, puis excluez simplement les ID lorsque vous faites get_terms.