Thursday, September 22, 2022
HomeWordPress Developmentcustomized taxonomy - wp_get_object_terms rely on taxonomies inside an class archive

customized taxonomy – wp_get_object_terms rely on taxonomies inside an class archive


Engaged on a class archive, i’ve a sidebar with customized non hierarchical taxonomies, used as filters (like customized post_tags).

With the intention to record these filters, I take advantage of wp_get_object_terms:

<?php
international $wp_query;
$posts = array();

foreach( $wp_query->posts as $publish ){
    $posts[] = $post->ID;
}

$matieres = wp_get_object_terms($posts, 'matieres');

if( rely($matieres)<1 ){
    ?>
    <div>No filterable publish</div>
    <?php
} else {
?>
    <div class="accordion">
        <div class="accordion-item">
            <h5>
                <button class="accordion-button" kind="button" data-bs-toggle="collapse" data-bs-target="#collapseMatieres" aria-expanded="true" aria-controls="collapseMatieres">
                    Matières
                </button>    
            </h5>
            <div id="collapseMatieres" class="accordion-collapse collapse present">
                <div class="accordion-body">
            <?php
            foreach( $matieres as $matiere ){
            ?>
             <div class="form-check">
              <enter class="form-check-input filter_check" kind="checkbox" data-filtre="matieres" worth="<?php echo $matiere->slug; ?>">
              <label class="form-check-label" for="flexCheckChecked">
                <?php echo $matiere->identify . ' (' . $matiere->rely . ')'; ?>
              </label>
            </div>           
            <?php
            }
            ?>
                </div> 
            </div> 
        </div>        
    </div> 
<?php
}
?>

All the things works fantastic, however for every customized taxonomy, wordpress counts me ALL posts in all classes, and never solely posts throughout the present class.

In image under, you possibly can see it in motion : on this class, i’ve solely 6 inox merchandise, however wp_get_object_terms counts me the 88 posts web site extensive.

enter image description here

Query is : what args ought to i cross with wp_get_object_terms to rely solely present class posts ?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments