Forums

Custom Fields Values printing the word "array" (6 posts)

  1. SJezek111
    Member
    Posted 8 months ago #

    Hi there,

    I'm having an incredibly frustrating time trying to figure this out. I've tried just about everything.

    I'm developing a site on my localhost with windows vista. (I'm not sure if this has anything to do with the problem)

    Everything I've tried to print or echo values of a custom field is only returning the word "array".

    <?php $styles = get_post_meta($post->ID, 'style', false); ?>
    	<ul>
    		<?php foreach($styles as $style) {
    			echo '<li>'.$style.'</li>';
    			} ?>
    	</ul>

    Returns:

    <ul><li>Array</li></ul>

    Help!!!

  2. Big Bagel
    Member
    Posted 8 months ago #

    Looks like $styles is an array of arrays then. You can use var_dump() to see exactly how $styles is structured:

    echo '<!--' . var_dump( $styles ) . '-->';

    Do you have multiple values associated with your custom field 'style'? Using

    get_post_custom_values( 'style', $post->ID );

    or

    get_post_meta( $post->ID, 'style', true );

    might be better depending on your custom fields.

  3. SJezek111
    Member
    Posted 8 months ago #

    Thanks for getting back to me.

    I tried the var_dump() and it returned null
    The other two strings returned nothing.

    ?

  4. Big Bagel
    Member
    Posted 8 months ago #

    Sorry! I always forget that var_dump() outputs on it's own. Do:

    echo '<!--';
    var_dump( $styles );
    echo '-->';

    That should properly show exactly how $styles is being populated.

  5. SJezek111
    Member
    Posted 8 months ago #

    Actually I figured it out!

    I'm using advanced custom fields plugin, and didn't think that the call would be different.

    It turns out that it's pretty simple. Who knew?!

    <?php the_field('style'); ?>

    Thanks for your help. :)

  6. Big Bagel
    Member
    Posted 8 months ago #

    Awesome. I actually helped someone out recently who was using that plugin and had a similar problem. Glad it's fixed.

Reply

You must log in to post.

About this Topic