2017-10-04 43 views
0

以下列出了所有条款,我可以帮助修改它,以便显示除活动/当前页面以外的所有条款吗?谢谢。显示除当前页面以外的所有条款

$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>'; 
    } 
} 

回答

0

你可以做这样的事情:

// 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 

所以,如果你按照我的意见,应该是明确的,但基本上你想要得到目前的职位条件和ID存储在数组中,那么只需在执行get_terms时排除ID。

相关问题