• I recently upgraded a client site from 2.9.2 to 3.0.1 in order to take advantage of the custom post types. It seems as if it broke something that used to work. In the single.php template, I had been retrieving an array of custom fields outside of the loop. I can use single custom fields… those still work. But retrieving and array no longer works. Instead I get this PHP error message:

    Warning: Invalid argument supplied for foreach() in /home/.sites/4/site38/web/wp-content/themes/NATOW_theme/single.php on line 54

    Here is the questionable code that was working up until I upgraded:

    <?php
    $custom_fields = get_post_custom();
    $my_custom_field = $custom_fields['didYouKnow'];
     foreach ( $my_custom_field as $key => $value ) // this is 'line 54' that breaks the script
    echo '<li>' . $value . '</li>';
    ?>

    I’ve tried a few different things and nothing worked.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I am experiencing the same issue. I am using custom_fields on a page like so:

    $custom_fields = get_post_custom(get_the_ID());
    
    ...
    
    <?php print $custom_fields['start'][0].' - '.$custom_fields['end'][0]; ?>

    But now:

    die($custom_fields == null);  // == 1

    Any help would be appreciated.

    Upon further inspection, it seems that my problem is with get_the_ID(); not returning the proper id of the page.

    Apparently this function is not supposed to work outside “the loop”, which is where I had it previously (and it was working). I just moved it inside the loop and now it works.

    Thread Starter guerrilladigital

    (@guerrilladigital)

    I need to use this outside of the main loop… how can i use this within single.php? outside of the loop? i tried to make a new query, and i keep getting errors.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Upgraded to WP 3.0.1 and something used to work, but doesn't.’ is closed to new replies.