[Solved] How to show all the posts/pages URLs of a WP site (like sitemap)?

  

3
Topic starter

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....

Thanks

1 Answer
2

Here is the code:

$allPostsWPQuery = new WP_Query( array(
    'post_type'      => 'post',
    'post_status'    => 'publish',
    'posts_per_page' => - 1
) ); ?>
 
<?php if ( $allPostsWPQuery->have_posts() ) : ?>
 
    <ul>
        <?php while ( $allPostsWPQuery->have_posts() ) : $allPostsWPQuery->the_post(); ?>
            <li><a href="<?php the_permalink(); ?>"><?php the_permalink(); ?></a></li>
        <?php endwhile; ?>
    </ul>
    <?php wp_reset_postdata(); ?>
<?php else : ?>
    <p><?php _e( 'There no posts to display.' ); ?></p>
<?php endif; ?>

On line #2 instead of:

'post_type'=>'page'

you can type:

'post_type'=>'post'

to see all the posts of your site.

Here is the result in the browser:

wordpress function to show posts and/or pages

Share: