GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   wordpress coders: question (https://gfy.com/showthread.php?t=887503)

fris 02-12-2009 02:17 PM

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

?>

daniel_webcams 02-12-2009 03:24 PM

hi...
Because in the second you extract something from the data base... and display the results by applying the filters to format the results...

The first one is not working first, because you don't have content (you don't take out anything from the data base)... this is the reason

fris 02-12-2009 08:39 PM

cause global $post saves $post->ID; $post->post_content; etc and everything from the current post, figured it would do the same

Libertine 02-12-2009 09:10 PM

Quote:

Originally Posted by fris (Post 15486459)
cause global $post saves $post->ID; $post->post_content; etc and everything from the current post, figured it would do the same

Doesn't $post->post_content give the content without formatting, just like get_the_content()?

If so, you might want to check this out: http://www.web-templates.nu/2008/08/...th-formatting/


All times are GMT -7. The time now is 10:49 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123