skip to Main Content

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

Answers


  1. Chosen as BEST ANSWER

    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


  2. 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; ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search