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 running a custom query below each post, to get other post from its category. Now I want to exclude the current post. This is my Query:

<?php // related_posts();
$exclude_post   = $post->ID;
$cats =  get_the_category();
//$cats[0]->term_id;$cats[1]->term_id; //name
 global $post;
 $newQuery = new WP_Query('posts_per_page=5&orderby=rand&cat='.$cats[0]->term_id.'&post__not_in='.array($exclude_post).''); 
 if ( $newQuery->have_posts() ):?>
    <ul>
    <?php
    while ( $newQuery->have_posts() ) : $newQuery->the_post(); ?>
        <li>
            <a title="<?php the_title();?>" href="<?php the_permalink();?>"><?php the_title();?></a>

        </li>
    <?php
    endwhile;?>
    </ul>
<?php        
endif;
?>

Now my query shows 0 results. The same, if I set the post which shall be excluded testwise to 1 or so.

What could be the error in my custom query?

Cheers Lars

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

You are trying to supply an array as part of the string query parameter. You could instead just supply the arguments list as an array like this:

$newQuery = new WP_Query( 
    array( 
        'posts_per_page' => 5, 
        'orderby' => 'rand', 
        'cat' => $cats[0]->term_id, 
        'post__not_in' => array($exclude_post)
    )
); 
share|improve this answer
    
Thanks man ;) excatly what i needed! –  Sagive SEO Mar 16 '12 at 23:10
add comment

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.