• Resolved beduicom

    (@beduicom)


    Hi!

    I’ve inserted this code in archive.php:

    <?php
      $mykey_values = get_post_custom_values('distance');
      foreach ( $mykey_values as $key => $value ) {
        echo "($value km)";
      }
    ?>

    but I get this warning:
    “PHP Warning: Invalid argument supplied for foreach() in D:\Sites\Bedui\www\wordpress\wp-content\themes\retromania\archive.php on line 44 PHP Warning: Invalid argument supplied for foreach() in D:\Sites\Bedui\www\wordpress\wp-content\themes\retromania\archive.php on line 44 “

    Can anyone see what I’ve done wrong?

    The custom value is a certain number of kilometers that I’ve cycled on that day. ??

    Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • <?php
      $mykey_values = get_post_custom_values('distance', $post->ID);
      foreach ( $mykey_values as $key => $value ) {
        echo "($value km)";
      }
    ?>
    Thread Starter beduicom

    (@beduicom)

    Thanks! It works for the single.php, but for the index.php I get this error:

    PHP Warning: Invalid argument supplied for foreach() in wordpress\wp-content\themes\retromania\index.php on line 18 PHP Warning: Invalid argument supplied for foreach() in wordpress\wp-content\themes\retromania\index.php on line 18 PHP Warning: Invalid argument supplied for foreach() in wordpress\wp-content\themes\retromania\index.php on line 18

    And for the archive.php I get this error:
    PHP Warning: Invalid argument supplied for foreach() in wordpress\wp-content\themes\retromania\archive.php on line 44

    Line 18 and Line 44 is this line in both those pages:
    foreach ( $mykey_values as $key => $value ) {

    Do you know why I get error like that?

    (I use this line right after the title of a post in both the single.php, archive.php and index.php – your code works fine for the single.php, but not for the archive.php and the index.php.

    Thanks a bunch if you can help me!

    <?php
      $mykey_values = get_post_custom_values('distance', $post->ID);
      if(is_array($mykey_values)):
         foreach ( $mykey_values as $key => $value ) {
           echo "($value km)";
         }
      endif;
    ?>
    Thread Starter beduicom

    (@beduicom)

    Awesome! That solved everything ??

    you’re almost welcome. ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘get_post_custom_values problem – receives error on page?’ is closed to new replies.