Limit a query to just 4 Posts, not very usual Query!!!!
-
Hello everybody! I have this query which just shows posts which are in the same taxonomy as the posts which is just shown!!! (so this Code definitely belongs on a single.php-Page). It’s working super nice and perfect but just one thing is messed up. The limitation with “showposts” just works FOR EACH TERM OF A TAXONOMY not for ALL POSTS SHOWN here in general…but I want to LIMIT it to 4 Posts shown, no matter how many posts would belong for each term of the same taxonomy. Hope you understand me. Please help me I’m really bad in PHP…sorry!
<?php
global $post;
$terms = get_the_terms( $post->ID , ‘workcap’, ‘string’);
$do_not_duplicate[] = $post->ID;if(!empty($terms)){
foreach ($terms as $term) {
query_posts( array(
‘workcap’ => $term->slug,
‘showposts’ => 4,
‘caller_get_posts’ => 1,
‘post__not_in’ => $do_not_duplicate ) );
if(have_posts()){
while ( have_posts() ) : the_post(); $do_not_duplicate[] = $post->ID; ?><div id=”twentyleft”>
<div id=”post-<?php the_ID(); ?>” class=”related_work_post”><div>” title=”<?php the_title() ?>” class=”linked”><?php $image = get_post_meta($post->ID, “Image1”, true); echo $image; ?></div>
<h3>” title=”<?php the_title() ?>” class=”linked”><?php the_title() ?></h3>
<?php $subtitle = get_post_meta($post->ID, “Subtitle”, true); echo $subtitle; ?></div>
</div><!– twentyleft END –>
<?php endwhile; wp_reset_query();
}}}
?>
- The topic ‘Limit a query to just 4 Posts, not very usual Query!!!!’ is closed to new replies.