Skip to content

Instantly share code, notes, and snippets.

@jcobb
Created June 21, 2012 02:52
Show Gist options
  • Save jcobb/2963530 to your computer and use it in GitHub Desktop.
Save jcobb/2963530 to your computer and use it in GitHub Desktop.
WordPress $post logging function
<?php
function log_post($post){
$p_title = $post->post_title;
$p_type = $post->post_type;
$p_cat = get_the_category( $post->ID );
$summary = '<strong>Post Title: </strong>' . $p_title;
$summary .= ' | <strong>Post Type:</strong> ' . $p_type;
if($p_cat){
$count= 0;
foreach($p_cat as $cat){
if($count == 0){
$summary .= ' | <strong>Post Categories:</strong> ' . $cat->cat_name;
}
else{
$summary .= ', ' .$cat->cat_name;
}
$count++;
}
}
echo '<details style="background:#fff; margin-bottom:10px; padding:10px; color:#111; font-family:monospace; font-size:12px; border:1px solid #555" class="clearfix">';
echo '<summary>' . $summary .'</summary>';
echo '<pre>' . htmlentities(print_r($post, true)) . '</pre>';
echo '</details>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment