Problem with the custom fields (coding issue)
-
I am trying to pull a video from youtube and post it OVER the <?php the_title(); ?> area. This is the code I’m using for the custom fields (I have this code in single.php) in order to do that:
<?php $custom_fields = get_post_custom(0); $my_custom_field = $custom_fields['media']; foreach ( $my_custom_field as $key => $value ) { echo $value; } ?>
Now this is fine, it works…however if I do not actually provide a custom value (because I just don’t want a video on some posts) – it shows this error:
Warning: Invalid argument supplied for foreach() in /public_html/whatever.com/wp-content/themes/nuaw/single.php on line 12.
So essentially what is happening is it has a problem with this line of code when I don’t supply a video for the post:
foreach ( $my_custom_field as $key => $value ) {
Any ideas on how I can not provide a video on some posts and eliminate the error?
- The topic ‘Problem with the custom fields (coding issue)’ is closed to new replies.