Skip to content

Instantly share code, notes, and snippets.

@everaldomatias
Created October 23, 2015 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save everaldomatias/15c693690f2d3dc1130e to your computer and use it in GitHub Desktop.
Save everaldomatias/15c693690f2d3dc1130e to your computer and use it in GitHub Desktop.
Loop separando os posts por terms
<?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;
}
?>
@everaldomatias
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment