How to Get Posts, Including Private Ones?

Currently in one of my php files, I retrieve all of the public posts like this:

$posts = get_posts(array(
    'posts_per_page' = -1,
    'post_type' = 'post'
));

However, this only returns public posts, and I would like to store all posts, both public and private, in the $posts variable. How can I accomplish this?

Topic get-posts posts Wordpress

Category Web


Set the post_status argument to an array of desired post status strings, or to the string any to query regardless of status entirely:

$posts = get_posts(array(
    'posts_per_page' => -1,
    'post_type'      => 'post',
    'post_status'    => array( 'publish', 'private' ),
));

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.