How can I filter blog posts by author?

2019-07-24 00:05发布

I'll use have_posts function to fetch messages, how can I filter posts by author name?

标签: php wordpress
4条回答
We Are One
2楼-- · 2019-07-24 00:25

just append ?author=4 to the url

with the 4 being the author ID

查看更多
劫难
3楼-- · 2019-07-24 00:33

Another option would be to just skip posts in the loop that belong to a certain author. Like so:

<?php if (get_post_author($post) == "wade") continue; ?>

This would be useful if you are using multiple loops in a page and want to filter out certain users' posts without creating multiple WP_Querys.

查看更多
淡お忘
4楼-- · 2019-07-24 00:38

You can write your own query to include or exclude posts from an Author This page has documentation about the different options you can pass to a query. http://codex.wordpress.org/Template_Tags/query_posts

Here is an example to only get posts from the user 'wade'

$author_query = new WP_Query('author_name=wade');
查看更多
【Aperson】
5楼-- · 2019-07-24 00:48

There are a few plug-ins which can do this for you - such as this one

If they don't quite what you want, they should serve as a good starting point for writing your own plugin (which isn't that scary or difficult)

查看更多
登录 后发表回答