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.

In the function below, I'm trying to remove the current post from the output loop (since this is a list of "related" posts).

However, when I try to pass the current post $post->ID to the "post__not_in" parameter, all hell breaks loose.

Warning: array_map() [function.array-map]: Argument #2 should be an array in C:\xampplite\htdocs\theteareport\wp-includes\query.php on line 1826

Warning: implode() [function.implode]: Invalid arguments passed in C:\xampplite\htdocs\theteareport\wp-includes\query.php on line 1826

Warning: array_diff() [function.array-diff]: Argument #2 is not an array in C:\xampplite\htdocs\theteareport\wp-includes\query.php on line 2496

What is the proper method?

//get related posts by category
function ce4_get_related_by_category()
{
global $post;
$cat = implode(',',get_cats());
$catHidden=get_cat_ID('hidden');
$myqueryCurrent = new WP_Query();
//$myqueryCurrent->query(array('cat' => "$cat,-$catHidden",'post__not_in' => get_option('sticky_posts')));
$myqueryCurrent->query(array('cat' => "$cat,-$catHidden",'post__not_in' => $post->ID));
$totalpostcount = $myqueryCurrent->found_posts;
if($totalpostcount > 0)
    {
        echo "<ul>";
        $myposts = get_posts(array('cat' => "$cat,-$catHidden",'numberposts' => $cb2_current_count));
        foreach($myposts as $idx=>$post) 
        {
        ?>
            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><?php the_excerpt(); ?></li>
        <?php 
        }
        echo "</ul>";
    }
} 
share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

post__not_in only takes arrays - so it should such, even if you are only passing single value. Simply pass array($post->ID).

share|improve this answer
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.