Sunday, November 6, 2022
HomeWordPress Developmentcustomized put up sorts - Show 3 stage taxonomies

customized put up sorts – Show 3 stage taxonomies


Right here is basic guideline to get what you want.
Use get_term() to get 1st, 2nd and third stage phrases.Documentation right here and right here.

1st Degree: you possibly can show this listing of phrases instantly in php as follows

$taxonomy = "SOME_TAXONOMY";
$phrases = get_terms([
     'taxonomy' => $taxonomy,
     'parent' => 0,
     ]);


if ( ! empty( $phrases ) && ! is_wp_error( $phrases ) ) { ?>
<ul>
    <?php 
    foreach ($phrases as $time period) : ?>
        <li>
            <a href="https://wordpress.stackexchange.com/questions/332234/<?php echo get_term_link($term->term_id); ?>"><?php echo $term->identify; ?></a>
        </li>
    <?php endforeach; ?>
</ul>

2nd / third Degree Phrases
After displaying 1st stage phrases, it is best to use ajax motion to get baby phrases of clicked mum or dad time period. Move id of mum or dad time period to ajax motion perform. Documentation for utilizing Ajax with WordPress is right here.

Code for ajax motion ought to seem like this.

perform wp_ajax_child_terms_action(){

    $taxonomy = "SOME_TAXONOMY";
    $mum or dad = $_GET['id_of_parent_from_ajax'];
    $phrases = get_terms([
        'taxonomy' => $taxonomy,
        'parent' => $parent,
     ]);


    if ( ! empty( $phrases ) && ! is_wp_error( $phrases ) ) { ?>
       <ul>
           <?php foreach ($phrases as $time period) : ?>
            <li>
                 <a href="https://wordpress.stackexchange.com/questions/332234/<?php echo get_term_link($term->term_id); ?>"><?php echo $term->identify; ?></a>
            </li>
            <?php endforeach; ?>
      </ul>

<?php }  ?>

I hope this will likely allow you to begin.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments