How Do I Create an Archive PHP in WordPress?

Creating an archive of your WordPress posts is a great way to keep track of your blog’s history and keep your readers informed about what you’ve been writing about. You can create an archive by adding the following code to your WordPress theme’s functions.php file:

function archive_post(post_id) {

wp_archive_create( ”, ‘posts’ );


When you create an archive, you will be given the post_id of the post you want to archive. You can then use this post_id to retrieve the post from the archive.

To retrieve a post from the archive, you can use the get_post() function. For example, the following code will retrieve the post with the post_id of 2:.

get_post( 2 );

The get_post() function will return the post object, which you can then use to access the post’s content, comments, and more. You can also use the get_post_meta() function to retrieve post metadata, such as the post’s title and excerpt.

The archive_post() function will archive all posts in the posts table of the WordPress database. You can use the wp_unarchive_post() function to undo the effects of the archive_post() function.