Guest User

WordPress: List URLs for attachment, page, post, category

a guest
Aug 24th, 2015
198
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. include "wp-load.php";
  4.  
  5. /* You have 2 options in the line below:
  6.  
  7. status=publish
  8. ... will return posts and pages with type, URL and title,
  9.  
  10. status=any
  11. ... will return in addition any attachments such as images
  12. in that post immediately after in the list with URL and file name. */
  13.  
  14. $posts = new WP_Query('post_type=any&posts_per_page=-1&post_status=any');
  15. $posts = $posts->posts;
  16. $categories = get_categories('hide_empty=false');
  17.  
  18. header('Content-type:text/plain; charset=utf-8');
  19. foreach($posts as $post) {
  20.     switch ($post->post_type) {
  21.         case 'attachment':
  22.             $permalink = get_attachment_link($post->ID);
  23.             break;
  24.         case 'page':
  25.             $permalink = get_page_link($post->ID);
  26.             break;
  27.         case 'post':
  28.             $permalink = get_permalink($post->ID);
  29.             break;
  30.         default:
  31.             $permalink = get_post_permalink($post->ID);
  32.             break;
  33.     }
  34.     echo "\n{$post->post_type}\t{$permalink}";
  35. }
  36. foreach ($categories as $cat) {
  37.              
  38.         $id = get_the_ID();
  39.         $category = get_the_category($id);
  40.  
  41.         echo "\ncategory\t";
  42.         echo ''.get_option('home').'/'.get_option('category_base').'/'.$cat->category_nicename.'';
  43. }
  44. ?>
RAW Paste Data