• Resolved xstortionist

    (@xstortionist)


    This has become frustrating for me. I’ve created a custom field with meta box for a subhead line that goes underneath a page title. I’m using this code to output the text within the page I’m editing.

    <?php $subhead = get_post_meta($post->ID, 'subheadline', true);
                if($subhead) {
    				echo '<p>' . $subhead . '</p>';
    			}
    			?>

    Instead of the subhead line outputting, the only text that shows up is “array” is this code correct? What am I doing wrong?

    Oddly enough, I can use default custom field and it will output just fine.

    http://wordpress.org/extend/plugins/wck-custom-fields-and-custom-post-types-creator/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter xstortionist

    (@xstortionist)

    I even just tried to echo and still nothing :*(

    <?php echo get_post_meta($post->ID, 'subheadline', true); ?>

    Plugin Author madalin.ungureanu

    (@madalinungureanu)

    Hi xstortionist,

    If you look at the first question in the FAQ of the plugin you will find the answer. Basically WCK stores it’s custom fields in an array even if you only have one value.

    So basically you will need something like this:

    <?php $subhead = get_post_meta($post->ID, 'subheadline', true);
                if(!empty($subhead)) {
                    foreach( $subhead as $sub ){
    		    echo '<p>' . $sub['insert your slug here'] . '</p>';
                    }
    	    }
    ?>

    Thread Starter xstortionist

    (@xstortionist)

    Thank you Madalin! I greatly appreciate the help. I’m really new to all of this PHP stuff, I’ve been a front end designer for a long time and I’m transitioning into being a programmer now. This is going to help me out a lot. Thank you so much!

    Thread Starter xstortionist

    (@xstortionist)

    So if I am correct.

    $subhead is a collection of data for the custom field

    $sub is an item within that collection of data

    foreach, place the data in <p> tags

    What is [‘insert your slug here’] ? what would I put in there? The customfield name?

    Plugin Author madalin.ungureanu

    (@madalinungureanu)

    Hi,

    You can see the slug for a field in the Custom Fields Creator, in the Meta Box Fields metabox under the Field Title of a field you created, highlighted in yellow with the text “Slug:” before it. Basically it’s the field name with lower case, “-” instead of spaces and no accents.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Field Outputs Array instead of actual content’ is closed to new replies.