CodingHelp with MySQL (i think) problem?

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  Kenny J (WINGNUTKJ)  
 To:  Jo (JELLS)      
31182.13 In reply to 31182.1 
The offending function is get_posts() in the wp-includes folder. Like Matt, says, the LIMIT bit at the end should have a valid value. In my version, the code is:

PHP code:
 
function get_posts($args) {
	global $wpdb;
	parse_str($args, $r);
	if ( !isset($r['numberposts']) )
		$r['numberposts'] = 5;
	if ( !isset($r['offset']) )
		$r['offset'] = 0;
	if ( !isset($r['category']) )
		$r['category'] = '';
	if ( !isset($r['orderby']) )
		$r['orderby'] = 'post_date';
	if ( !isset($r['order']) )
		$r['order'] = 'DESC';
 
	$now = current_time('mysql');
 
	$posts = $wpdb->get_results(
		"SELECT DISTINCT * FROM $wpdb->posts " .
		( empty( $r['category'] ) ? "" : ", $wpdb->post2cat " ) .
		" WHERE post_date <= '$now' AND (post_status = 'publish') ".
		( empty( $r['category'] ) ? "" : "AND $wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $r['category']. " " ) .
		" GROUP BY $wpdb->posts.ID ORDER BY " . $r['orderby'] . " " . $r['order'] . " LIMIT " . $r['offset'] . ',' . $r['numberposts'] );
 
	update_post_caches($posts);
 
	return $posts;
}
 


That suggests to me that if it can't find a value, it'll default to 5.

Kenny
The Wisdom of YouTube comments:
Bright Eyes - When The President Talks To God
Not bad. I thought this song might be anti-God, but it seems more to be against the president, which is cool by me.
0/0
 Reply   Quote More 

 From:  Jo (JELLS)   
 To:  Kenny J (WINGNUTKJ)     
31182.14 In reply to 31182.13 
quote:
The offending function is get_posts() in the wp-includes folder


Is that the name of the file? I'm looking at the contents of my wp-includes folder and i don't know what file i should be looking for...

ETA: Right, found the file in question and it says exactly what yours does.

I'll try upgrading to 2.0.5 - probably not tonight, however. I hate messing with databases and just don't feel like attempting that right now.
0/0
 Reply   Quote More 

 From:  Kenny J (WINGNUTKJ)  
 To:  Jo (JELLS)      
31182.15 In reply to 31182.14 

Sorry about that; my mind was kind of mush last night. It's in functions.php, as you've found.

 

I'm not a PHP expert, but I'm wondering if there's some condition where the variable is set to null, or an empty string or something, so it passes the isset() test, but doesn't show up in the string.

 

What say the PHP experts?


Kenny
The Wisdom of YouTube comments:
Bright Eyes - When The President Talks To God
Not bad. I thought this song might be anti-God, but it seems more to be against the president, which is cool by me.
0/0
 Reply   Quote More 

 From:  Matt  
 To:  Kenny J (WINGNUTKJ)     
31182.16 In reply to 31182.15 

Without seeing how the function arguments are handled it's hard to say for sure.

 

But, if that is the only test they're performing on the data then they need to add more. At the moment a variable could be an empty string and it would pass their basic checks.

doohicky

0/0
 Reply   Quote More 

 From:  Kenny J (WINGNUTKJ)  
 To:  Matt     
31182.17 In reply to 31182.16 
I'll have a look deeper into it tonight and try to trace the flow of it. If it was in the querystring as ?var=&someothervar=2 or something, would that pass the isset test?

Kenny
The Wisdom of YouTube comments:
Bright Eyes - When The President Talks To God
Not bad. I thought this song might be anti-God, but it seems more to be against the president, which is cool by me.
0/0
 Reply   Quote More 

 From:  Jo (JELLS)   
 To:  Kenny J (WINGNUTKJ)     
31182.18 In reply to 31182.17 
Out of curiosity, which version of WordPress are you using? 2.0.5?
0/0
 Reply   Quote More 

 From:  Kenny J (WINGNUTKJ)  
 To:  Jo (JELLS)      
31182.19 In reply to 31182.18 
I'm on 2.0.4 just now. I've not got round to updating to the new one yet.

Kenny
The Wisdom of YouTube comments:
Bright Eyes - When The President Talks To God
Not bad. I thought this song might be anti-God, but it seems more to be against the president, which is cool by me.
0/0
 Reply   Quote More 

 From:  Kenny J (WINGNUTKJ)  
 To:  Jo (JELLS)      
31182.20 In reply to 31182.18 
Oh and:

quote: Them
What’s new? We have about 50 or so bugfixes, which you can review on our dev tracker here, mostly minor bug fixes around feeds, custom fields, and internationalization.


Could be what you're after...

Kenny
The Wisdom of YouTube comments:
Bright Eyes - When The President Talks To God
Not bad. I thought this song might be anti-God, but it seems more to be against the president, which is cool by me.
0/0
 Reply   Quote More 

 From:  Jo (JELLS)   
 To:  Kenny J (WINGNUTKJ)     
31182.21 In reply to 31182.20 
Yeah... noticed that last night. I will get around to it... just a question of time more than anything else.
0/0
 Reply   Quote More 

 From:  Matt  
 To:  Kenny J (WINGNUTKJ)     
31182.22 In reply to 31182.17 
The isset() function is very similar to empty() except it can be used to tell if a variable is actually empty or if it contains a null char where as the empty() function cannot.

Even though PHP doesn't do explicit types you can still check the variable type and the data it contains using built in functions like is_numeric(), is_bool(), etc.

doohicky

0/0
 Reply   Quote More 

Reply to All    
 

1–20  21–22

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats