Jump to content

Simple help for broken PHP


robertsmith17

Recommended Posts

I'm a complete newbie with PHP - have been making some changes on a WordPress site and ran across an error "Warning: Invalid argument supplied for foreach() in /home/thesite/public_html/wp-content/themes/site1/custompost_entertainment.php on line 35"

 

if ($post->post_type == 'page'){
	echo apply_filters('the_content',$post->post_content);
	
	echo "<section id='featured_pages'>";
	
	foreach ($customPosts as $date=>$posts){
		$date = new DateTime($date);
		
		foreach ($posts as $page){
			$custom_meta = get_post_custom($page->ID);
			

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/276178-simple-help-for-broken-php/
Share on other sites

Not to mention $date=>$posts is not valid syntax.

 

it is if $posts contains the name of an object property

 

$arr = array ('a' => 100, 'b' => 200);
$obj = (object)$arr;

$x = 'a';
echo $obj->$x;  // 100
$x = 'b';
echo $obj->$x;  // 200

 

it is if $posts contains the name of an object property

 

$arr = array ('a' => 100, 'b' => 200);
$obj = (object)$arr;

$x = 'a';
echo $obj->$x;  // 100
$x = 'b';
echo $obj->$x;  // 200

 

Ahh, you are right.  I retract that statement, for some reason I read it as $date=>posts.  Like OP was trying to access an object variable.

Thanks for the replies, I really appreciate it.

 

I don't really understand the syntax of 

foreach ($customPosts as $date=>$posts){

 

 

Like I said - I'm a complete novice with PHP.

 

I'm a lot more comfortable with the likes of C#, where a foreach loop would be written something like this (for example):

foreach (String str in stringArray){

 

 

I'm afraid I just don't understand "$customPosts as $date=>$posts" at all. Could someone pseudo-code it for me? Or explain it in terms of C#/Java/JS type syntax?

 

Thanks again. Sorry for being a bit dense...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.