WordPress.org

Ready to get started?Download WordPress

Forums

Custom tax. query get_terms w/ multiple slugs? (1 post)

  1. astereo
    Member
    Posted 1 year ago #

    Hello everyone,
    I'm trying to see if this is possible or not. Currently I have an advanced "People" page that relies on a people custom post type, and a custom taxonomy called "peoplegroups" to break down staff. I then have a custom page template that sorts people depending on a number of options. The page settings for this page let a user check a box to sort all people and group them by term name (in which a foreach loop is used and works perfectly). If this option is not checked, than all of the people in the custom post type will be displayed and they won't be grouped by the custom taxonomy. This also works perfectly.

    The last option I'm trying to accomplish is displaying only SPECIFIC "people groups" as they are entered in a custom field. I've been trying to use the same foreach loop with some minor adjustments but it seems that you can not specify more than one targeted slug, so I'm not sure if this is possible or not. Code is below:

    Note the 'peoplecat' custom field is a standard text field from Advanced Custom Fields.

    <?php $terms = get_terms( 'peoplegroups', 'hide_empty=1&slug='.$peoplecat.'' );
    $count = count($terms);
    if ( $count > 0 ){
        foreach ( $terms as $term ) {
            echo '<h2 class="peopleterm">' . $term->name . '</h2>';
            echo '<div class="peoplesector">';
            $loop = new WP_Query( array(
                'post_type' => 'people',
                'post_per_page' => 100,
                'orderby' => 'date',
                'order' => 'ASC',
                'tax_query' => array(
                    array(
                        'taxonomy' => 'peoplegroups',
                        'field' => 'id',
                        'terms' => $term->term_id
                    )
                )
            ));
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic