0
votes

I've been trying for hours to display a sub taxonomy and I'm almost there

I have the titles displaying but I want the sub taxonomy description showing aswell,

this is in WordPress

<?php
//first get the current term
$current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

//then set the args for wp_list_categories
$args = array(
    'child_of' => $current_term->term_id,
    'taxonomy' => $current_term->taxonomy,
    'hide_empty' => 0,
    'hierarchical' => true,
    'depth'  => 1,
    'title_li' => '',
);

?>
<?php  foreach ( $args as $arg ) { ?>
    <div class="col-md-6">
        <article>
            <header class="entry-header">
                <h2><?php wp_list_categories( $args ); ?></h2>
            </header>
        </article>
    </div>
<?php } ?>

I've tried to add a for each as well which didn't work XD

please is anyone could help it would be awesome

                        <?php
                        $cat_args   = array(
                            'taxonomy' => 'business_categories',
                            'orderby'  => 'name',
                            'order'    => 'ASC',
                            'number'=> 2,
                        );
                        $categories = get_categories( $cat_args );

                        foreach ( $categories as $category ) {

                            ?>
                            <div class="col-md-6">
                                <h3>
                                    <a href="<?= get_category_link( $category->term_id ) ?>"><?= $category->name ?></a>
                                </h3>
                                <p>
                                    <a href="<?= get_category_link( $category->term_id ) ?>"><?= $category->category_description ?></a>
                                </p>

                            </div>
                            <!--    <pre>
                            <?php print_r( $categories ); ?>
                        </pre>  -->

                        <?php } ?>

this is how I'm displaying my taxonomy

2
If you need a function that does not format the results, try get_categories() - While1
On which page are you trying to show? - Bhautik
archive.php so I have the taxonomy then when I click into one of the taxonomy categories i want the sub category of that taxonomy - ashley gibson

2 Answers

0
votes

Try somthing like this

<?php 
  $categories = get_categories( $args );
?>
... 
<?php foreach ( $categories as $term ): ?>
    <div class="col-md-6">
        <article>
            <header class="entry-header">
                <h2><?php echo $term->name; ?></h2>
                <p><?php echo $term->description; ?></p>
            </header>
        </article>
    </div>
<?php endforeach; ?>
0
votes

I got the answer

the get get_category_link only displays the HTML title output

<?php
$current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$args         = get_terms( array(
   'orderby'  => 'name',
   'order'    => 'ASC',
   'taxonomy' => $current_term->taxonomy,
   'child_of' => $current_term->term_id,
) );
foreach ( $args as $arg ) { ?>
                   <div class="col-md-6">
                       <article>
                           <header class="entry-header">
                               <h2><a href="<?= get_term_link( $arg->term_id ) ?>"><?php echo $arg->name ?></a></h2>
                           </header>
                           <p><a href="<?= get_term_link( $arg->term_id ) ?>"( $arg->term_id ) ?>"><?php echo $arg->description ?></a></p>
                       </article>
                   </div>
<?php } ?>
           </div>
       </div>



hopefully, this will help anyone in a similar situation