• Resolved Emily1

    (@emily1)


    I finally have the right code, I think, to get my address custom field to show on each post. The problem is that not all of my posts have addresses. The posts without an address have an error that says Warning: Invalid argument supplied for foreach() in /data/16/1/37/96/1852748/user/2011364/htdocs/wp-content/plugins/thesis-openhook/functions.php(453) : eval()’d code on line 5.

    Here is the code I’m using:

    <?php
      global $post;
      $custom_fields = get_post_custom(0);
      $address = $custom_fields['address'];
      foreach ( $address as $key => $value )
        echo $key . " : " . $value . "<br />";
    ?>

    How should I modify it so that it doesn’t try to show the address field for posts without an address field?

    Also, the output comes out something like this:

    0 : 3208 Wellington Ct., Ste. 109, Raleigh, NC 27615

    How do I change the 0 to say Address?

Viewing 2 replies - 1 through 2 (of 2 total)
  • if ( $address ) {
      foreach ( $address as $key => $value )
        echo $key . " : " . $value . "<br />";
    }

    Try this on the 0 issue

    if ( $address ) {
      foreach ( $address as $key => $value )
        echo "Address: " . $value . "<br />";
    }

    Thread Starter Emily1

    (@emily1)

    Thanks very much!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom Fields’ is closed to new replies.