Retrieve posts by author

时间:2011-04-15 作者:rexposadas

我正在尝试检索当前用户创建的所有自定义帖子类型。

我有一段代码:

wp_get_current_user();

$args_my_items = array(
    \'posts_per_page\' => 10,
    \'post_type\' => \'mycustomposttype\',
    \'post_author\' => $current_user->ID);

query_posts($args_my_items);
最终返回的是所有类型为“mycustomposttype”的帖子。它不按post\\u作者过滤。

我是否使用了错误的查询参数?如何按当前用户筛选?

谢谢

1 个回复
最合适的回答,由SO网友:keatch 整理而成

您必须指定author 参数如上所述here. 尝试使用:

$args_my_items = array(
    \'posts_per_page\' => 10,
    \'post_type\' => \'mycustomposttype\',
    \'author\' => $current_user->ID
);

query_posts($args_my_items);

结束

相关推荐