1

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>";
    }
} 

1 Answer 1

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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