Embed code error with custom fields

I have inserted the embed code custom fields into a single-[post type].php file (twenty eleven theme) and all works fine except for custom fields that use radio buttons, check boxes or drop down select options for the data input on a custom post type.

I get the following error:

Warning: Invalid argument supplied for foreach()

  • david10
    • Flash Drive

    The error message is:

    Warning: Invalid argument supplied for foreach() in /home/david99/public_html/mydomain.com/wp-content/themes/twentyeleven/single-posttype.php on line 25

    An example of an embed code for a custom taxonomy is:

    <?php echo get_the_term_list( $post->ID, 'customtaxonomyID', 'Before: ', ', ', 'After' ); ?>

    Do you need anything else?

    Thanks for you help.

  • Timothy
    • Chief Pigeon

    Hey again.

    Is that the code on line 25?

    Is this the code provided in the Custom Press admin?

    Perhaps you could include the code before and after so I can see?

    You can use PasteBin if needed:


    Can I also confirm which WP version and plugin version are you using? And have you checked for conflicts by disabling all other plugins and testing?


  • david10
    • Flash Drive

    I got everything working. I may have lost some functionality/flexibility because I removed part of the embed code but so far it is working. In case others have the same issue, below is what I did.

    The original embed code from CustomPress was:

    <?php if ( get_post_meta( $post->ID, 'unique code', true ) ) { foreach ( get_post_meta( $post->ID, 'unique code', true ) as $value ) { echo $value . ', '; }} ?>

    I changed it to

    <?php get_post_meta( $post->ID, 'unique code', true ) ?>

  • Timothy
    • Chief Pigeon

    Hey there.

    Great to see you got it working.

    The “if” is checking the function has data before looping through to get the data. Then passing it through the echo statement. You might have issues here with no data and if there are multiple items (which the loop is for).

    Take care.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.