Make WordPress Core

Opened 16 years ago

Closed 15 years ago

#7014 closed defect (bug) (invalid)

get_post_custom() doesn't always return an array

Reported by: donncha's profile donncha Owned by:
Milestone: Priority: high
Severity: normal Version: 2.5.1
Component: General Keywords: 2nd-opinion
Focuses: Cc:

Description

I have noticed that get_post_custom() doesn't always return an array. wp-includes/feed.php uses this function in a foreach loop at line 164 in WP 2.5.1 resulting in an error message stating "Invalid argument supplied for foreach() in ...wp-includes/feed.php on line 164"

I think update_postmeta_cache() in wp-includes/post.php should cast it's return value as an array possibly.

Change History (6)

#2 @donncha
16 years ago

Casting the return of get_post_custom() as an array fixes this problem.

#3 @ryan
16 years ago

  • Milestone changed from 2.5.2 to 2.9

Milestone 2.5.2 deleted

#3 @Denis-de-Bernardy
15 years ago

  • Milestone changed from 2.9 to 2.8

seems invalid:

	foreach ( (array) $ids as $id ) {
		if ( ! isset($cache[$id]) )
			$cache[$id] = array();
	}

	foreach ( (array) array_keys($cache) as $post)
		wp_cache_set($post, $cache[$post], 'post_meta');

or am I missing something?

#4 @Denis-de-Bernardy
15 years ago

  • Keywords 2nd-opinion added
  • Milestone changed from 2.8 to Future Release

#5 @Denis-de-Bernardy
15 years ago

  • Milestone changed from Future Release to 2.9
  • Priority changed from normal to high

#6 @Denis-de-Bernardy
15 years ago

  • Milestone 2.9 deleted
  • Resolution set to invalid
  • Status changed from new to closed

returns an array even with a non-existing post.

Note: See TracTickets for help on using tickets.