SHARE
TWEET

Output last edited page details from Wordpress

hiddenpeanuts Dec 18th, 2013 659 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. //This outputs a tab-delimited list of the 50 last modified pages, suitable for importing into a spreadsheet.
  4. //By Chad Haefele (chad.haefele@gmail.com), December 2013
  5. //Inspired by the top answer here: http://stackoverflow.com/questions/3464701/export-list-of-pretty-permalinks-and-post-title
  6. //Query built with http://wpquerygenerator.com/
  7.  
  8. include "wp-load.php";
  9.  
  10.         //Add column headers:
  11.         echo "\nPage Title\tURL\tLast Modified Date\tLast Author";
  12.        
  13.         //Build the query and get the results:
  14.         $custom_query = new WP_Query(array(
  15.                 'post_type' => 'page',
  16.                 'orderby' => 'modified',
  17.                 'posts_per_page' => 50,
  18.                 'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1
  19.         ));
  20.  
  21.         //Loop through the results and display them, tab-delimited:    
  22.         if ( $custom_query->have_posts() ) {
  23.                 while ( $custom_query->have_posts() ) {
  24.                         $custom_query->the_post();
  25.                         //Extract necessary fields:
  26.                         $mod_date = get_the_modified_date();
  27.                         $title = get_the_title();
  28.                         $url = get_page_link();
  29.                         $mod_author = get_the_modified_author();
  30.                        
  31.                         echo "\n{$title}\t{$url}\t{$mod_date}\t{$mod_author}"; 
  32.                 }
  33.         } else {
  34.         echo "Error: No pages met your query's criteria.";
  35.         }
  36. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top