Anyone know why one of them is working and one isnt?
im just counting the number of images in a post
Quote:
<?
// doesnt work
function postcount() {
global $post;
$content = $post->post_content;
preg_match_all('/<img/', $content, $images);
echo count($images[0]);
}
// works
function postcount() {
global $wpdb, $id;
$post = $wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = $id");
$post_content = apply_filters('the_content', $post);
preg_match_all('/<img/', $post_content, $images);
echo count($images[0]);
}
?>
|