Uncategorized

Extracting wordpress posts as text

This is a simple script I wrote that outputs WordPress posts on one page as text. A client needed this because they were editing the copy of the site and wanted all of it in a Word file. You can copy and paste the results or print them to pdf.

This is quick and dirty but it does the job. You may need to alter it for your purposes.

Results:

";

while($row=mysql_fetch_array($result)){
if(!is_numeric($k)){
echo "

".$row['post_title']."

Category: ".get_category($row['post_parent'])."

".$row['post_date']."

".$row['post_content']."
";
}
echo "


";
}

function get_category($parent){
$sql="SELECT post_title FROM wp_posts WHERE post_parent = $parent" ;
$result=mysql_query($sql) or die(mysql_error());
$row=mysql_fetch_array($result);
return $row[0];
}
?>

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.