Reputation: 1860
How can I query for all posts with any status (published, pending etc.) for a given author 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
));
?>
Should I provide new as the status? I visited this (link http://codex.wordpress.org/Post_Status_Transitions) and got this ['new' - When there's no previous status]. I set the status as new and it solved my problem. But I am not sure will it make any problem in future? will it show all posts for ever? I have very little experience in WP. Please help me out.
Upvotes: 1
Views: 13034
Reputation: 1261
you can use
<?php
$author_posts = get_posts(array(
'author' => $post->post_author,
'post__not_in' => array($post->ID),
'posts_per_page' => 5
));
?>
<div class="graybg">
<div class="container">
<div class="row listrecent listrelated">
<!-- begin post -->
<?php
for ($i = 0; $i < 3; $i++) {
$_post = $author_posts[$i];
?>
<div class="col-md-4">
<div class="card">
<a href="post.html">
<img class="img-fluid img-thumb" src="#" alt="">
</a>
<div class="card-block">
<h2 class="card-title"><a href="<?php echo $_post->guid; ?>"><?php echo $_post->post_title; ?></a></h2>
<div class="metafooter">
<div class="wrapfooter">
<span class="meta-footer-thumb">
<a href="author.html">
<img class="author-thumb" src="<?php echo get_avatar_url($_post->post_title); ?>" alt="<?php echo get_author_name($_post->post_author); ?>">
</a>
</span>
<span class="author-meta">
<!-- <span class="post-name"><a href="author.html"><?php echo get_the_author_description($_post->post_title); ?></a></span><br /> -->
<span class="post-date">22 July 2017</span><span class="dot"></span><span class="post-read">6 min read</span>
</span>
<span class="post-read-more"><a href="post.html" title="Read Story"><svg class="svgIcon-use" width="25" height="25" viewbox="0 0 25 25">
<path d="M19 6c0-1.1-.9-2-2-2H8c-1.1 0-2 .9-2 2v14.66h.012c.01.103.045.204.12.285a.5.5 0 0 0 .706.03L12.5 16.85l5.662 4.126a.508.508 0 0 0 .708-.03.5.5 0 0 0 .118-.285H19V6zm-6.838 9.97L7 19.636V6c0-.55.45-1 1-1h9c.55 0 1 .45 1 1v13.637l-5.162-3.668a.49.49 0 0 0-.676 0z" fill-rule="evenodd"></path>
</svg></a></span>
</div>
</div>
</div>
</div>
</div>
<!-- end post -->
<?php } ?>
Upvotes: 0
Reputation: 39872
Try asking this at http://wordpress.stackexchange.com. They tend to be better about WP API questions there. I'll take a stab myself though.
According to their docs the following values are valid. I would try 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.
Upvotes: 2