Answers for "Get taxonomies"

PHP
0

show all terms of a custom taxonomy

$terms = get_terms( array(
  'taxonomy' => 'taxonomy_name_or_slug',
  'hide_empty' => true,
) );
foreach ($terms as $term){
  echo $term->slug;
  echo $term->name;
  echo "<br><br>";
}
Posted by: Guest on July-20-2020
0

Get taxonomies

$index_query = new WP_Query(array('post_type' => 'company', 'posts_per_page' => '-1', 'order' => 'DESC'));

while ($index_query->have_posts()) : $index_query->the_post();

    $taxonomy_ar = get_the_terms($post->ID, 'tax-name');

    $output = '<span class="btn">';
    foreach($taxonomy_ar as $taxonomy_term) {
        $output .= '<a href="'.get_term_link($taxonomy_term->slug, 'title').'">'.$taxonomy_term->name.' <span class="label">'.$taxonomy_term->count.'</span></a> ';
    }
    $output .= '</span>';

    echo $output;

endwhile;​
Posted by: Guest on September-26-2021

Browse Popular Code Answers by Language