List custom post type of various taxonomies

Asked

Viewed 551 times

5

I used that code:

<ul>
<?php
    $args = array(
        'post_type' => 'integrante',
        'orderby' => 'title',
        'order'   => 'asc',
        'lang' => 'pt',
        'tax_query' => array(
        'relation' => 'AND',
            array(
                'taxonomy' => 'integrante_category',
                'field'    => 'slug',
                'terms'    => array( 'equipe_fundador','equipe_financas' )

            ),
        ),
    );
    $query = new WP_Query( $args );
    while ( $query->have_posts() ) : $query->the_post();
?>

<li>
  <h3 class="nome"><?php the_title(); ?></h3>
</li>

<?php endwhile; wp_reset_query();?>
</ul>

It returns all the posts of the two taxonomies I put in. However, I need it to include a division (title) between one taxonomy and another, thus would have the mark of where begins the loop of each one.

  • pq not make two separate loops?

  • I ended up doing this. But my question was whether there was another way. In this case, I have 10 categories, so I did 10 loops.

  • you can try to sort the Wp_query results in some way... a flag inside the loop might solve, the question is sorting. I’ll give a thought here

1 answer

1

Make a loop of categories where you insert the category header, within this loop you will get the ids of all categories, use this to make one more loop of posts, creating a pair of nested loops, avoiding having to use 10 different loops.

I’m gonna codate something for you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.