WordPress category or taxonomy list

WordPress custom taxonomy term list with function and loop. show taxonomy team on wp query loop

We can show all category by simple WordPress default function. like this –

<?php wp_list_categories(); ?>

It has some Parameters to customize more. you can check details here on wp developer reference

Also we can use PHP loop to show more customize way

<?php 
$categories = get_categories( array(
    'orderby' => 'name',
) );
    
foreach ( $categories as $category ) {
    printf( '<a href="%1$s">%2$s</a><br />',
        esc_url( get_category_link( $category->term_id ) ),
        esc_html( $category->name )
    );
}
?>

You can also use same parameter here on the array as wp_list_categories. Now what about custom taxonomy? No worries it very simple as previous code.

<?php

// Taxonomy Loop

$terms = get_terms( array(
        'taxonomy'   => 'custom_taxonomy_name', //custom taxonomy name
        'hide_empty' => true, 
));

echo '<ul>';

// Loop through all terms with a foreach loop
foreach( $terms as $term ) {
    // Use get_term_link to get terms permalink
    // USe $term->name to return term name
    echo '<li><a href="'. get_term_link( $term ) .'">'. $term->name .'</a></li>';
}

echo '</ul>'; 
?>

To Show term inside the wp query loop will be

<?php 
the_terms( int $id, string $taxonomy, string $before = '', string $sep = ', ', string $after = '' ) 
//or simple use
the_terms( get_the_ID() , 'category' ,'', ', ','' );
?>

Show on single post

 <?php
$terms = get_the_terms( $post->ID , 'custom_taxonomy_name' );
foreach ( $terms as $term ) {
  echo $term->slug;
}
?>
Previous Code

Most View or Popular Post on WordPress

WordPress Post query by user views without plugin ...

Next Code

WordPress Related Post

Show related post on blog single page or any custo ...

0 Comment

    Leave a Reply

    Your email address will not be published.

    3 × 1 =

    WooCommerce Mostly used Shortcode

    Most use shortcode for popular eCommerce plugin Wo ...

    WordPress Next and Previous Post

    WordPress Next and Previous Post navigation for cu ...

    Protected: WP user Login Notification

    This code is Protected. Contact Admin for password

    WordPress Ajax Search without plugin [ Easy ]

    WordPress Ajax Search without plugin. Fully custom ...

    HTML img tag to HTML SVG tag [WordPress]

    Image to SVG for WordPress. Generate svg code from ...

    ACF

    JavaScript

    jQuery

    Others

    PHP

    WooCommerce

    WordPress

    skype

    Need Coding Help?

    Connect Skype
    top