• Resolved christopherburton

    (@christopherburton)


    I am using WPAlchemy for a custom meta box and I need it to echo
    <p class="description">Here is a description</p>

    However, it returns this instead:
    <p class="description">Array</p>

    Here is the PHP I am using:

    <?php
    $meta = $custom_metabox->the_meta('description', TRUE);
    	if ($meta):
           	echo '<p class="description">'.$meta.'</p>'; ?>
    <?php endif; ?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • The value of $meta is an array. To find out what it contains add var_dump( $meta ); before the echo and you will get the contents of the array.

    Thread Starter christopherburton

    (@christopherburton)

    @chris Nice! Now how can I strip out everything that var_dump($meta); returns and only echo the text?

    Post the result of the var_dump. It it’s indexed it will be something like echo $meta[0]; Where 0 is the index of the text.

    Thread Starter christopherburton

    (@christopherburton)

    <?php
    $meta = $custom_metabox->the_meta('description', TRUE);
    	if (!empty($meta)):
    	var_dump($meta);
           	echo '<p class="description">'.$meta.'</p>'; ?>
    <?php endif; ?>

    Returns:

    <pre class='xdebug-var-dump' dir='ltr'>
    <b>array</b> <i>(size=1)</i>
      'description' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'This upright formal script was inspired by the 1960's and <a href="https://doyaldyoung.com">Doyald Young</a>.'</font> <i>(length=108)</i>
    </pre>

    My Goal Output:
    <p class="description">This upright formal script was inspired by the 1960's and <a href="https://doyaldyoung.com">Doyald Young</a></p>

    Changing the echo line to:

    echo '<p class="description">'.$meta['description'].'</p>'; ?>

    Should work.

    To get a better understanding how Arrays work see: https://php.net/manual/en/language.types.array.php

    Thread Starter christopherburton

    (@christopherburton)

    Thanks, Chris. I appreciate your time and thanks for the link as well.

    I removed var_dump() and it seemed to work.

    Final Code:

    <?php
    	$meta = $custom_metabox->the_meta('description', TRUE);
    		if (!empty($meta)):
           		echo '<p class="description">'.$meta['description'].'</p>'; ?>
    <?php endif; ?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WPAlchemy Returns "Array"’ is closed to new replies.