I am entering this code into my post
[php]
header('Content-type: text/plain');
global $wpdb;
[/php]
<table>
<thead>
<tr>
<th> </th>
<th>Posts</th>
<th>Avg. Length</th>
<th>Total Length</th>
<th>Comments (Mine)</th>
</tr>
</thead>
<tbody>
[php]
for ($i = intval(date('Y')); $i >= 2002; $i--) {
$from = $i;
$to = $i + 1;
$posts_count = $wpdb->get_var("
SELECT COUNT(*)
FROM <code>wp_posts</code>
WHERE post_date >= '$from-01-01'
AND post_date < '$to-01-01'
AND post_status = 'publish';
");
$posts_length_avg = $wpdb->get_var("
SELECT AVG(LENGTH(post_content))
FROM <code>wp_posts</code>
WHERE post_date >= '$from-01-01'
AND post_date < '$to-01-01'
AND post_status = 'publish';
");
$posts_length_total = $wpdb->get_var("
SELECT SUM(LENGTH(post_content))
FROM <code>wp_posts</code>
WHERE post_date >= '$from-01-01'
AND post_date < '$to-01-01'
AND post_status = 'publish';
");
$comments_total = $wpdb->get_var("
SELECT COUNT(*)
FROM <code>wp_comments</code>
WHERE comment_date >= '$from-01-01'
AND comment_date < '$to-01-01'
AND comment_approved = '1';
");
$comments_mine = $wpdb->get_var("
SELECT COUNT(*)
FROM <code>wp_comments</code>
WHERE comment_date >= '$from-01-01'
AND comment_date < '$to-01-01'
AND comment_approved = '1'
AND user_ID = 1;
");
[/php]
<tr>
<td>[php] echo $i; [/php]</td>
<td>[php] echo number_format($posts_count, 0); [/php]</td>
<td>[php] echo number_format($posts_length_avg, 0); [/php]</td>
<td>[php] echo number_format($posts_length_total, 0); [/php]</td>
<td>[php] echo number_format($comments_total, 0); [/php] ([php] echo number_format($comments_mine, 0); [/php])</td>
</tr>
[php]
}
[/php]
</tbody>
</table>
And the code is giving the desired results. However, when I preview the post the raw html (source code)is displayed instead of my website. What is going wrong?
http://wordpress.org/extend/plugins/allow-php-in-posts-and-pages/