Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save carlaizumibamford/a9517d70159445a772fbc0beeacc271e to your computer and use it in GitHub Desktop.

Select an option

Save carlaizumibamford/a9517d70159445a772fbc0beeacc271e to your computer and use it in GitHub Desktop.
Display posts by author, using author id:
$query = new WP_Query( array( 'author' => 123 ) );
Display posts by author, using author ‘user_nicename‘:
$query = new WP_Query( array( 'author_name' => 'rami' ) );
Show Posts From Several Authors
Display posts from several specific authors:
$query = new WP_Query( array( 'author' => '2,6,17,38' ) );
Exclude Posts Belonging to an Author
Display all posts except those from an author(singular) by prefixing its id with a ‘-‘ (minus) sign:
$query = new WP_Query( array( 'author' => -12 ) );
Multiple Author Handling
Display posts from multiple authors:
$query = new WP_Query( array( 'author__in' => array( 2, 6 ) ) );
You can also exclude multiple author this way:
$query = new WP_Query( array( 'author__not_in' => array( 2, 6 ) ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment