Show the terms of the hierarchical taxonamy

93 Views Asked by At

I'm trying to display buttons with category term names. i am using this code which works to show terms of categories which without hierarchy, but i can't figure out how to adjust it for hierarchical ones

$tipi_evento_names = dci_tipi_evento_array();
?>

<div class="container py-5">
    <h2 class="title-xxlarge mb-4">Esplora per categoria</h2>
    <div class="row g-4">
        <?php print_r($tipi_evento_names);
        foreach ($tipi_evento_names as $tipi_evento_name) {
            $args = array('post_type' => 'evento',
                'posts_per_page' => -1,
                'tax_query' => array(
                    array(
                        'taxonomy' => 'tipi_evento',
                        'field' => 'name',
                        'terms' => $tipi_evento_name,
                        'hierarchical' => 'true',
                        'hide_empty' => '0',

                    ),
                ),
            );
            $servizi = get_posts($args);
            $categoria = get_term_by('name', $tipi_evento_name, 'tipi_evento');

            $url = get_term_link( $categoria->term_id, 'tipi_evento');
        ?>
        <div class="col-md-6 col-xl-4">
            <div class="cmp-card-simple card-wrapper pb-0 rounded border border-light">
                <div class="card shadow-sm rounded">
                    <div class="card-body">
                        <a class="text-decoration-none" href="<?php //echo $url; ?>" data-element="service-category-link">
                            <h3 class="card-title t-primary"><?php echo $categoria->name ; ?></h3>
                        </a>
                        <p class="text-secondary mb-0">
                            <?php //echo $categoria->description; ?>
                        </p>
                    </div>
                </div>
            </div>
        </div>
        <?php } ?>
    </div>
</div>

I used print_r to see what it returns <?php print_r($tipi_evento_names);

and this is the arrey

Array ( [Cultural event] => Array ( [Artistic event] => Array ( [0] => Festival [1] => Exhibition [2] => Theater show [3] => Dance show [4] => Musical event [5] => Guided tour [6] => Reading (public) [7] => Film screening [8] => Free visit ) [Education event] => Array ( [0] => Summer school/ winter [1] => Webinar [2] => Seminar [3] => Workshop [4] => Book presentation [5] => Course ) [Conference and Summit] => Array ( [0] => Conference [1 ] => Summit [2] => Congress ) [Information Day] => Array ( [0] => Open Day ) ) [Social Event] => Array ( [Competition and Ceremony] => Array ( [0] => Ceremony [1] => Contest/competition ) [Public debate] => Array ( [0] => Public debate/dialogue [1] => Forum ) [Meeting with experts] => Array ( [0] => Meeting of experts [1] => Hackathon / Datathon ) [Community Gathering] => Array ( [0] => Parade [1] => Festival [2] => Historical Tournament or Palio [3] => Patronal Feast or Saints [ 4] => Market [5] => Commemoration ) [Religious event] => Array ( [0] => Jubilee [1] => Jubilee audience [2] => Procession [3] => Religious celebration [4] = > Religious reading [5] => Religious gathering [6] => Sanctification ) ) [Political event] => Array ( [Public meeting] => Array ( [0] => Congress or party meeting [1] => Procession or strike [2] => Election rally ) ) [Business or commercial event] => Array ( [Fair or Show] => Array ( [0] => Fair or Show [1] => Exhibition or Global Exhibition ) [ Business meeting] => Array ( [0] => Business meeting [1] => Convention [2] => Round table ) [Seasonal commercial event] => Array ( [0] => End of season sale ) ) [Sports Event] => Array ( [Sports Event] => Array ( [0] => Match [1] => Race or Tournament or Competition [2] => Excursion [3] => Sports Gala [4] => Racing [5] => Sports rally ) ) )

these are the errors i get:

  1. Warning: Attempt to read property "term_id" on bool on line 27
  2. Warning: Attempt to read property "name" on bool on line 34

I'm customizing a WordPress theme and I don't have much experience, could you tell me what I'm doing wrong or how to do it? I took this code (and adapted it by changing the name of the taxonomy) from another file of my theme which does the same thing I have to do in this other one, the only difference I noticed is that I want to do this the terms of the taxonomy are hierarchical, while in the other they are not.

0

There are 0 best solutions below