List all the pages, posts, categories, and custom ones on WordPress

You can create a static page template for this like page-allurls.php:

<?php

$urls = array();

$post_types = get_post_types(array( 'public' => true ));
foreach ($post_types as $post_type) {
  if ( $post_type == "attachment" ) continue;

  $posts = get_posts( array('numberposts' => -1, 'post_type' => $post_type));
  foreach ($posts as $post) {
    $post_link                     = get_permalink($post->ID);
    $urls[$post_link]['type']      = "post";
    $urls[$post_link]['id']        = $post->ID;
    $urls[$post_link]['slug']      = $post->post_name;
    $urls[$post_link]['title']     = $post->post_title;
    $urls[$post_link]['post_type'] = $post->post_type;
    $urls[$post_link]['cat']       = $post->post_type;
  }
}


$taxonomies = get_taxonomies('', 'names');
foreach ($taxonomies as $taxonomy) {
  $terms = get_terms($taxonomy);
  foreach ($terms as $term) {
    $term_link                    = get_term_link($term);
    $urls[$term_link]['type']     = "term";
    $urls[$term_link]['id']       = $term->term_id;
    $urls[$term_link]['slug']     = $term->slug;
    $urls[$term_link]['title']    = $term->name;
    $urls[$term_link]['taxonomy'] = $taxonomy;
    $urls[$term_link]['cat']      = $taxonomy;
  }
}


echo "<table>";
foreach ($urls as $url => $info) {
  echo "<tr><td>".$info['cat']."</td><td>$url</td></tr>";
}
echo "</table>";

Code language: PHP (php)

Posted

in

,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.