get_posts by id not working

时间:2012-10-27 作者:Pam Apple

我有以下代码:

global $post;
$current_post = $post->ID;
$array=range(1,$current_post);
$posts = get_posts(\'numberposts=5&post__in=\' . $array . \'&category=\'. $category->term_id . \'&exclude=\' . $current_post);
出现的错误为Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/todaytra/public_html/depmua/wp-includes/query.php on line 2159

有人能指出我的$数组valiable的错误吗?

感谢您的帮助:)

1 个回复
SO网友:Pam Apple

我刚刚找到了另一种解决方案:

global $post;
$current_post = $post->ID;
$array=range(1,$current_post);
$args = array(
\'numberposts\'     => 5,
\'offset\'          => 0,
\'category\'        => $category->term_id,
\'orderby\'         => \'ID\',
\'order\'           => \'DESC\',
\'exclude\'         => $current_post,
\'post_type\'       => \'post\',
\'post_status\'     => \'publish\',
\'suppress_filters\' => true,
\'post__in\' => $array );

$posts = get_posts($args);
我不知道为什么以前的方法不起作用。无论如何,我已经解决了这个问题。感谢@imHavoc和@userabuser查看我的问题:)

结束