Wordpress按作者id获取帖子
如何查询给定作者ID的所有状态(已发布、待定等)的帖子Wordpress按作者id获取帖子,wordpress,loops,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' => '???', /
<?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
));
?>
我应该提供新的身份信息吗?我访问了这个(链接),得到了这个['new'-当没有以前的状态时]。我将状态设置为新,它解决了我的问题。但我不确定将来会不会有什么问题?它会永远显示所有帖子吗?我在WP方面的经验很少。请帮帮我。试试问这个。他们倾向于更好地回答WP API问题。不过我自己也要试试
根据它们的特性,以下值是有效的。我会尝试任何
'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.
你可以用
<?php
$author_posts = get_posts(array(
'author' => $post->post_author,
'post__not_in' => array($post->ID),
'posts_per_page' => 5
));
?>
1976年7月22日分钟阅读
请解释什么工作不正常-不是每个人都可以测试代码以查看错误,而且很难通过查看来查看错误。有关示例代码,请参阅。
<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 } ?>