Get full list of posts/pages for one author

The following short code will help you get all posts from a current logged user.

$args = array(
            'post_type' => 'post', // this can be changed to any(for all), page(for pages) or other custom post type
            'posts_per_page' => '-1',
            'post_status' => 'publish', //this status will take only published posts. You can use any status
            'author'=>get_current_user_id()
        );
$my_query = new WP_Query($args);

If you wish to get a specific user posts just use the following code:

$args = array(
            'post_type' => 'post', // this can be changed to any(for all), page(for pages) or other custom post type
            'posts_per_page' => '-1',
            'post_status' => 'publish', //this status will take only published posts. You can use any status
            'author'=>[id of the user] // replace [id of the user] with the ID number of user
        );
$my_query = new WP_Query($args);

You can also use the Author name to get all users posts. This is the code for this:

$args = array(
            'post_type' => 'post', // this can be changed to any(for all), page(for pages) or other custom post type
            'posts_per_page' => '-1',
            'post_status' => 'publish', //this status will take only published posts. You can use any status
            'author_name'=>'[name of the user]' // replace [name of the user] with the username of user
        );
$my_query = new WP_Query($args);

Leave a Reply

Your email address will not be published. Required fields are marked *