• Hi,I am new to programming.

    If you look at the following blog https://outdooractivitiesforkids.com/wordpress/?p=3 I get the following error

    Warning: Invalid argument supplied for foreach() in /home/a6228915/public_html/wordpress/wp-content/themes/positie_1/index.php on line 11

    and LINE 11 in index.php says:

    1. <?php get_header(); ?>
    2.
    3. <?php include(TEMPLATEPATH.”/sidebar.php”);?>
    4.
    5. <!– begin content –>
    6. <div id=”main”>
    7. <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    8. <h1><?php the_title(); ?></h1>
    9.
    10. <? $postimg = get_post_meta($post->ID, “pre_image”, false); ?>
    11. <? foreach($postimg as $image) {
    12. echo “<img class=\”fullimg\” src=\””.$image.”\” />”;
    13. } ?>
    .
    .
    .
    .
    .

    Please help how do I fix it. I want pictures in my blog.

Viewing 5 replies - 1 through 5 (of 5 total)
  • That would make me think <? $postimg = get_post_meta($post->ID, "pre_image", false); ?> returned nothing.

    add <?php print_r($postimg);?> after that to see what’s returned.

    Also a good habit to use <?php rather than <?.

    Also, please note I’ve delete your other thread that mentions this same error.

    Thread Starter sbscheema

    (@sbscheema)

    Are you saying insert the line you gave me between line 10 & 11… like this

    10. <? $postimg = get_post_meta($post->ID, “pre_image”, false); ?>
    <?php print_r($postimg);?>
    11. <? foreach($postimg as $image) {

    Sorry for double posting ( in threads)

    Yes. I’m guessing that it will display NOTHING. You do have custom fields with ‘pre_image’, correct?

    Related:
    Using_Custom_Fields

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘error in line <? foreach($postimg as $image)’ is closed to new replies.