0

I am trying to make my loop go through the posts that are associated with these terms. Currently nothing is being output.

<?php

    $args = array(
        'post_type' => 'staff',
        'posts_per_page' => '-1',
        'tax_query' => array(
                array(
                    'taxonomy' => 'staff',
                    'field' => 'slug',
                    'terms' => array(
                                    'editor-in-chief',
                                    'managing-editor',
                                    'fiction-editor',
                                    'poetry-editor',
                                    'nonfiction-editor',
                                    'production-manager'
                                )
                )
            )
    );
    $my_query = new WP_Query( $args );

        if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post();
        ?>

                    <div class="loop four columns">
                        <div class="column-nest">
                            <h5 class="staff-title big-top-space"><?php the_field('staff_title'); ?></h5>
                            <h6 class="staff-name  bottom-space"><?php the_field('staff_member_name'); ?></h6>              
                        </div> <!-- column-nest -->
                        <figure class="staff-photo-border">
                            <img class="column-nest" src="<?php the_field('staff_member_photo'); ?>" alt="photo of <?php the_field('staff_member_name'); ?>" />
                        </figure> <!-- staff-photo-border -->
                    </div> <!-- loop four columns -->


        <?php the_content(); ?>
        <?php endwhile; endif; ?>

2 Answers 2

0

Using has_term() requires the name of the taxonomy as a parameter.

References:

0

You don't have to use the loop for terms. Use tax_query instead. Here is the codex link : http://codex.wordpress.org/Class_Reference/WP_Query

You arguments should be

    $args = array(
    'post_type' => 'staff',
    'posts_per_page' => '-1',
    'tax_query' => array(
            array(
                'taxonomy' => 'taxonomy_slug',
                'field' => 'slug',
                'terms' => array(
                                'editor-in-chief',
                                'managing-editor',
                                'fiction-editor',
                                'poetry-editor',
                                'nonfiction-editor',
                                'production-manager'
                            )
            )
        )
);

Change "taxonomy_slug" to the right slug.

Cheers!

2
  • Hey Jeff thanks for the help! I made some edits see above original post to see where I am hung up. Feb 18, 2014 at 17:03
  • Are you sure the taxonomy slug is the same as the post type? Thanks Feb 18, 2014 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.