Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using this code to load related posts with a custom taxonomy term slug:

<?php
global $post;
$terms = get_the_terms( $post->ID , 'topics', 'string');
$do_not_duplicate[] = $post->ID;

if(!empty($terms)){
    foreach ($terms as $term) {
        query_posts( array(
        'topics' => $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; ?>

But I always get more than 4 posts. How can I really set this query to just 4 posts?

Thanks!

AD

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You need to specify number of posts to retrieve. 'showposts' is how many to show on page, and is deprecated (use 'posts_per_page' instead)

'showposts' => 4,
'numberposts' => 4,
share|improve this answer

thanks!

This works:

<?php
global $post;
$terms = get_the_terms( $post->ID , 'topics', 'string');
$do_not_duplicate[] = $post->ID;

if(!empty($terms)){
    foreach ($terms as $term) {
        query_posts( array(
        'topics' => $term->slug,
        'numberposts' => 4,
        'posts_per_page' => 4,
        'caller_get_posts' => 1,
        'post__not_in' => $do_not_duplicate ) );
        if(have_posts()){
            while ( have_posts() ) : the_post(); $do_not_duplicate[] = $post->ID; ?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.