Created
October 23, 2015 00:31
-
-
Save everaldomatias/15c693690f2d3dc1130e to your computer and use it in GitHub Desktop.
Loop separando os posts por terms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = array( 'hide_empty=0' ); | |
$funcoes = get_terms( 'posicao', $args ); | |
if ( ! empty( $funcoes ) && ! is_wp_error( $funcoes ) ) { | |
$count = count( $funcoes ); | |
foreach ( $funcoes as $funcao ) { | |
$output_terms .= $funcao->term_id . ','; | |
} | |
} | |
$explode_terms = explode( ",", $output_terms); | |
array_pop( $explode_terms ); | |
foreach( $explode_terms as $category ): | |
$args = array( | |
'post_type' => 'elenco', | |
'posts_per_page' => -1, | |
'tax_query' => array( | |
'relation' => 'AND', | |
array( | |
'taxonomy' => 'categoria_do_elenco', | |
'field' => 'name', | |
'terms' => 'profissional' | |
), | |
array( | |
'taxonomy' => 'posicao', | |
'field' => 'id', | |
'terms' => $category | |
) | |
) | |
); | |
$posts = new WP_Query( $args ); | |
if ( $posts->have_posts() ) { | |
while ( $posts->have_posts() ) { | |
$posts->the_post(); | |
get_template_part( 'content', 'elenco-archive' ); | |
} | |
} | |
endforeach; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Junto com isso eu uso o plugin https://wordpress.org/support/plugin/taxonomy-terms-order para ordenar via admin a ordem que o loop deve apresentar os terms da taxonomia.