WP Query in wordpress


Show Posts for one Author

Display posts by author, using author id:

$query = new WP_Query( 'author=123' );

Display posts by author, using author ‘user_nicename’:

$query = new WP_Query( 'author_name=rami' );

Show Posts From Several Authors

Display posts from several specific authors:

$query = new WP_Query( '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( 'author=-12' );
Advertisements