How can I filter blog entries by an author?

I will use the has_posts function to retrieve messages, how can I filter messages by author name?

+1
source share
4 answers

You can write your own request to include or exclude messages from the author. On this page there is documentation about the various parameters that you can pass to the request. http://codex.wordpress.org/Template_Tags/query_posts

Here is an example to receive messages only from user wade '

$author_query = new WP_Query('author_name=wade');
+6
source

There are several plugins that can do this for you - such as this one.

, , ( )

+1

Another option is to simply skip the messages in the loop that belong to a particular author. For example:

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

This would be useful if you use multiple loops on a page and want to filter out messages from specific users without creating multiple WP_Querys.

+1
source

just add? author = 4 in URL

when 4 is the identifier of the author

+1
source

Source: https://habr.com/ru/post/1716287/


All Articles