Wordpress按作者ID获取帖子

时间:2011-12-09 14:00:51

标签: wordpress loops

如何针对给定的作者ID查询具有任何状态(已发布,待处理等)的所有帖子。

<?php               
$loop = new WP_Query( array(
    'post_type' => 'photo',
    'posts_per_page' => 12,
    'orderby'=> 'menu_order',
    'author' => $user->data->ID,
    'post_status' => '???', //what should I put here
    'paged'=>$paged
));
?>

我应该提供新的状态吗?我访问了这个(链接http://codex.wordpress.org/Post_Status_Transitions)并得到了这个['新' - 当没有以前的状态时]。我将状态设置为新状态,它解决了我的问题。但是我不确定它将来会出现什么问题?它会永远显示所有帖子吗?我对WP的经验很少。请帮帮我。

2 个答案:

答案 0 :(得分:1)

尝试在http://wordpress.stackexchange.com询问此问题。他们倾向于更好地了解那里的WP API问题。我会自己捅一下。

根据他们的docs,以下值有效。我会尝试any

'publish' - a published post or page.
'pending' - post is pending review.
'draft' - a post in draft status.
'auto-draft' - a newly created post, with no content.
'future' - a post to publish in the future.
'private' - not visible to users who are not logged in.
'inherit' - a revision. see get_children.
'trash' - post is in trashbin (available with Version 2.9).
'any' - retrieves any status except those from post types with 'exclude_from_search' set to true.

答案 1 :(得分:0)

您可以使用

    $('#btnSyncDictionary').click(function (event) {
    $.ajax({
        type: "POST",
        url: "HealthPanel/SyncDictionary",
        headers: { "RequestVerificationToken": $('input[name="__RequestVerificationToken"]').val() }
    });

    event.stopImmediatePropagation();
    event.stopPropagation();
});


<?php
    $author_posts =  get_posts(array(
'author' => $post->post_author,
'post__not_in' => array($post->ID),
'posts_per_page' => 5
));

?>
相关问题