How can i list the categories of a post type, the taxonomy

How can i retrive the categories from a post_type that i select.

I have a Custom_field – categorie_serial

Read More
<?php

$values = get_field('categorie_serial');
if($values)
{
    echo '<ul>';

    foreach($values as $value)
    {
        echo '<li>' . $value . '</li>';
    }

    echo '</ul>';
}

// always good to see exactly what you are working with
var_dump($values);

?>

This code retrive me the categories but it retrive me an error
The line 40 is “foreach($values as $value)”

    Warning: Invalid argument supplied for foreach() in /home/****/public_html/****/wp-content/themes/movies/tabserial/detali-serial.php on line 40

string(334) "Gen SerialeActiuneAnimatieAventura" 

How can i retrive the only the parent categories?
I do not want to retrive Gen Seriale – categoriy , only Actiune..


RESOLVED:

<?php 
$terms = get_terms('seriale','child_of=668');foreach ($terms as $term) {echo '<a href="'.get_term_link($term).'">'.$term->name.'</a>';}
?>

Related posts

Leave a Reply

2 comments

  1. This should get you started

    function my_cpt_cats() {
        $parent = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
        $args = array(
            'type'                     => 'post', 
            'child_of'                 => $parent->term_id,
            'parent'                   => '',
            'orderby'                  => 'slug',
            'order'                    => 'DESC',
            'hide_empty'               => 1,
            'hierarchical'             => 1,
            'exclude'                  => '',
            'include'                  => '',
            'number'                   => '',
            'taxonomy'                 => 'YOUR_TAXONOMY',
            'pad_counts'               => false 
        );
        $categories = get_categories( $args );
    }
    

    Remember to use your taxonomy name in the $args array.

  2. The solution for other. Thanks to Milo.

    668 – is the id of the category

    $terms = get_the_terms( $post->ID, 'seriale' );
    foreach( $terms as $term ):
        if( 668 == $term->parent ){
            echo '<a href="'.get_term_link($term).'">'.$term->name.'</a>';
        }
    endforeach;