By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy

Q: How to show all the posts/pages URLs of a WP site (like sitemap)?

+3 votes
Hi - I would like to know how to show all the URLs of all the posts (or/and pages) of a site (the CMS is WordPress).

Something like XML sitemap but showing all the pages permalinks on one WP page.

Maybe as a function....

asked in Web Development category by user hues

1 Answer

+2 votes

Here is the code:

$allPostsWPQuery = new WP_Query( array(
	'post_type'      => 'post',
	'post_status'    => 'publish',
	'posts_per_page' => - 1
) ); ?>

<?php if ( $allPostsWPQuery->have_posts() ) : ?>

		<?php while ( $allPostsWPQuery->have_posts() ) : $allPostsWPQuery->the_post(); ?>
            <li><a href="<?php the_permalink(); ?>"><?php the_permalink(); ?></a></li>
		<?php endwhile; ?>
	<?php wp_reset_postdata(); ?>
<?php else : ?>
    <p><?php _e( 'There no posts to display.' ); ?></p>
<?php endif; ?>

On line #2 instead of:


you can type:


to see all the posts of your site.

Here is the result in the browser:

wordpress function to show posts and/or pages

answered by user Jolie Ann
edited by user Jolie Ann