Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 02-12-2009, 02:17 PM   #1
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
Old 02-12-2009, 03:24 PM   #2
daniel_webcams
Confirmed User
 
daniel_webcams's Avatar
 
Industry Role:
Join Date: Nov 2008
Posts: 2,491
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
__________________
Daniel,

Skype: [email protected]
ICQ: 354-220-339
Email: daniel@adultforce[dot]com


daniel_webcams is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-12-2009, 08:39 PM   #3
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,359
cause global $post saves $post->ID; $post->post_content; etc and everything from the current post, figured it would do the same
__________________
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
Old 02-12-2009, 09:10 PM   #4
Libertine
sex dwarf
 
Libertine's Avatar
 
Join Date: May 2002
Posts: 17,860
Quote:
Originally Posted by fris View Post
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/
Libertine is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.