Permalink
Browse files

Better logic for the $meta_key. Make sure $image_html is set so it do…

…esn't throw an error.

git-svn-id: http://svn.locallylost.com/themes/hybrid-core/trunk@982 dba0f204-706d-4bc1-bc29-8b92e0485636
  • Loading branch information...
1 parent 78e363b commit 6299322fd0095122f32df184da17992cb866d67e greenshady committed Feb 15, 2012
Showing with 12 additions and 16 deletions.
  1. +12 −16 extensions/get-the-image.php
@@ -104,6 +104,9 @@ function get_the_image( $args = array() ) {
if ( !is_array( $image_cache ) )
$image_cache = array();
+ /* Set up a default, empty $image_html variable. */
+ $image_html = '';
+
/* If there is no cached image, let's see if one exists. */
if ( !isset( $image_cache[$key] ) || empty( $cache ) ) {
@@ -205,25 +208,18 @@ function get_the_image( $args = array() ) {
function get_the_image_by_meta_key( $args = array() ) {
/* If $meta_key is not an array. */
- if ( !is_array( $args['meta_key'] ) ) {
-
- /* Get the image URL by the single meta key. */
- $image = get_post_meta( $args['post_id'], $args['meta_key'], true );
- }
+ if ( !is_array( $args['meta_key'] ) )
+ $args['meta_key'] = array( $args['meta_key'] );
- /* If $meta_key is an array. */
- elseif ( is_array( $args['meta_key'] ) ) {
+ /* Loop through each of the given meta keys. */
+ foreach ( $args['meta_key'] as $meta_key ) {
- /* Loop through each of the given meta keys. */
- foreach ( $args['meta_key'] as $meta_key ) {
+ /* Get the image URL by the current meta key in the loop. */
+ $image = get_post_meta( $args['post_id'], $meta_key, true );
- /* Get the image URL by the current meta key in the loop. */
- $image = get_post_meta( $args['post_id'], $meta_key, true );
-
- /* If an image was found, break out of the loop. */
- if ( !empty( $image ) )
- break;
- }
+ /* If an image was found, break out of the loop. */
+ if ( !empty( $image ) )
+ break;
}
/* If a custom key value has been given for one of the keys, return the image URL. */

0 comments on commit 6299322

Please sign in to comment.