Skip to content

Instantly share code, notes, and snippets.

@aristath
Created October 14, 2013 09:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save aristath/6973063 to your computer and use it in GitHub Desktop.
<?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