• Resolved phnataly

    (@phnataly)


    ok, i have a custom post type LAW and two taxonomy LAW TYPE and EDITION I create a page taxonomy-law_type.php for display child terms LAW TYPE

    <ul class="wpb_page_list">
    <?php 
        $term = get_queried_object();
    
    $children = get_terms( $term->taxonomy, array(
        'parent'    => $term->term_id,
        'hide_empty' => false
    ) );
    
    if ( $children ) { 
        foreach( $children as $subcat )
        {
            echo '<li style="display:flex"><a href="' . esc_url(get_term_link($subcat, $subcat->taxonomy)) . '">' . // wrapped
              $subcat->name . ' (' . $subcat->count . ')' . '</a></li>';
        }
    }
    ?></ul>

    and page taxonomy-law_type-term.php

    <!-- Content -->
        <div id="content" class="content" role="main">
            <?php
            the_archive_description( '<div class="taxonomy-description">', '</div>' );
    
            if ( have_posts() ) {
                the7_archive_loop();
        } else {
                get_template_part( 'no-results', 'search' );
            }
        ?>
            <ul class="wpb_page_list">
    <?php 
        $term = get_queried_object();
    
    $children = get_terms( $term->taxonomy, array(
        'parent'    => $term->term_id,
        'hide_empty' => false
    ) );
    
    if ( $children ) { 
        foreach( $children as $subcat )
        {
            echo '<li style="display:flex"><a href="' . esc_url(get_term_link($subcat, $subcat->taxonomy)) . '">' . // wrapped
              $subcat->name . ' (' . $subcat->count . ')' . '</a></li>';
        }
    }
    ?></ul>
    
    </div><!-- #content -->

    But, if the post contains a term from taxonomy LAW TYPE and term from taxonomy EDITION, then on the page taxonomy-law_type-term.php, need to show the list terms of taxonomy EDITION in which there are posts for the current term taxonomy LAW TYPE. If note, show posts for current term taxonomy LAW TYPE

    Help please ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I’m not completely sure what you’re asking help with. For example, are you trying to do something with regards to querying for posts? Or with displaying other information from a given taxonomy, based on the current archive you’re presently viewing?

    At the moment, it feels like something to do with regards to a post that has terms from both taxonomies.

    Thread Starter phnataly

    (@phnataly)

    displaying other information from a given taxonomy, based on the current archive

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    You’re going to be able to get information for the given term in the way you’re already doing, with the queried object data. You’ll be able to get more from that specified term, which taxonomy it’s for and whatnot.

    At least in regards to each post listed, you would be able to fetch the currently rendered post ID with get_the_ID() and then use that to get various forms of term data from all associated taxonomies, if the given post has some, with get_the_terms() and start outputting returned data with that.

    Hopefully I’ve provided some insight, but if not quite, let me know.

    Thread Starter phnataly

    (@phnataly)

     
    // display child term of current term's parent taxonomy
    $term = get_queried_object();
    
    $children = get_terms( $term->taxonomy, array(
        'parent'    => $term->term_id,
        'hide_empty' => false
    ) );
    
    if ( $children ) { 
        foreach( $children as $subcat )
        {
            echo '<li style="display:flex"><a href="' . esc_url(get_term_link($subcat, $subcat->taxonomy)) . '">' . // wrapped
              $subcat->name . ' (' . $subcat->count . ')' . '</a></li>';
        }
    }
    
    // show term from taxonomy redaktsiya
    $terms = get_terms( array(
            'taxonomy'   => 'redaktsiya', // Swap in your custom taxonomy name
            'hide_empty' => true, 
    ));
    
    echo '<ul class="wpb_page_list">';
    
    // Loop through all terms with a foreach loop
    foreach( $terms as $term ) {
        // Use get_term_link to get terms permalink
        // USe $term->name to return term name
        echo '<li style="display:flex"><a href="'. get_term_link( $term ) .'">'. $term->name .'</a></li>';
    }
    
    echo '</ul>';

    but I don’t need to show not all posts with taxonomy ‘taxonomy’ => ‘redaktsiya’
    only those that relate to the current child term of current term’s parent taxonomy from TAXANOMY 1 and taxanomy redaktsiya

    Thread Starter phnataly

    (@phnataly)

    https://prnt.sc/23ocv1e
    how to show only posts that included to the current term 1 + term 2 taxonomy, not all records from the second taxonomy

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I think you’re either going to need to find a conditional case for your second get_terms() fetch to help limit exactly what terms to show, and I don’t have an answer for that.

    Since you’re mentioning showing only posts that include the current term 1 and term 2 taxonomy, it sounds like you need to check out the pre_get_posts hook to set up conditions in what it should be querying for.

    https://developer.www.ads-software.com/reference/hooks/pre_get_posts/

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom taxonomy: on the taxonomy term page show other taxonomy terms’ is closed to new replies.