View Single Post
Old 02-12-2009, 02:17 PM  
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,359
wordpress coders: question

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]);
}

?>
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote