SHARE
TWEET

List Wordpress posts and urls

a guest Mar 5th, 2012 3,347 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. staus= publish will return posts and pages with type, URL and title
  7. status= any will return in addition any attachments such as images
  8. in that post immediately after in the list with URL and file name  */
  9. $posts = new WP_Query('post_type=any&posts_per_page=-1&post_status=publish');
  10. $posts = $posts->posts;
  11.  
  12.  
  13. header('Content-type:text/plain');
  14. foreach($posts as $post) {
  15.     switch ($post->post_type) {
  16.         case 'revision':
  17.         case 'nav_menu_item':
  18.             break;
  19.         case 'page':
  20.             $permalink = get_page_link($post->ID);
  21.             break;
  22.         case 'post':
  23.             $permalink = get_permalink($post->ID);
  24.             break;
  25.         case 'attachment':
  26.             $permalink = get_attachment_link($post->ID);
  27.             break;
  28.         default:
  29.             $permalink = get_post_permalink($post->ID);
  30.             break;
  31.     }
  32.     echo "\n{$post->post_type}\t{$permalink}\t{$post->post_title}";
  33. }
  34. ?>
RAW Paste Data
Top