How to remove the current post from the query?

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.

Read More

Warning: array_map() [function.array-map]: Argument #2 should be an array in C:xampplitehtdocstheteareportwp-includesquery.php on line 1826

Warning: implode() [function.implode]: Invalid arguments passed in C:xampplitehtdocstheteareportwp-includesquery.php on line 1826

Warning: array_diff() [function.array-diff]: Argument #2 is not an array in C:xampplitehtdocstheteareportwp-includesquery.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>";
    }
} 

Related posts

Leave a Reply

1 comment