Where can I find the directory of all my posts/articles in WordPress?

Liyan Xu picture Liyan Xu · Mar 4, 2017 · Viewed 7.5k times · Source

I think all the posts should be in wp-content/uploads/... But I couldn't find them. Anyone has ideas of where my posts are located? Thanks!

Answer

Tyler Pope picture Tyler Pope · Mar 4, 2017

When you say "posts" are you referring to the default post type "post", (the post tab in your admin panel)?

If this is what you're referring to, you can access them directly through your database. All posts are stored in your database and not as actual files.

If you need to access them via your templates you can use one of two wordpress methods:

$args = array(
    'post_type' => 'post
);

The args array will be your settings for the queries.

$posts = get_posts($args);
print_r($posts); // this will give you 5 posts, you can increase the number with the argument 'posts_per_page' => x

you can loop through this data with a simple foreach.

The second method:

$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
    while ( $the_query->have_posts() ) {
         //post data (title, content, etc...)
    }
}