response to http://premium.wpmudev.org/forums/topic/how-do-i-use-multiple-loops-with-a-custom-taxonomy#post-527189
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 | |
function my_custom_posts_query( $taxonomy = '', $posts = '5', $post_type = 'post', $per_page = '4', $field = 'slug', $terms = 'news' ) { | |
$terms = get_terms( $taxonomy, 'showposts=' . $posts ); // for more details refer to codex please. | |
$args = array( | |
'post_type' => $post_type, | |
'posts_per_page' => $per_page, | |
'tax_query' => array( | |
array( | |
'taxonomy' => $taxonomy, | |
'field' => $field, | |
'terms' => $terms | |
) | |
) | |
); | |
$my_query = new WP_Query( $args ); | |
if( $my_query->have_posts() ) : | |
while ( $my_query->have_posts() ) : | |
$my_query->the_post(); | |
$cnt =0; | |
echo '<div class="bucket-post">' | |
$c++; | |
if( $c == 1) : | |
echo 'Some different content for my first post.'; | |
else : | |
echo 'The other post content.'; | |
endif; | |
echo '</div>'; | |
endwhile; | |
endif; | |
} | |
my_custom_posts_query( 'verticals', '5', 'post', '4', 'slug', 'news' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment