WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WPAlchemy Returns "Array" (7 posts)

  1. christopherburton
    Member
    Posted 2 years ago #

    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; ?>
  2. 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.

  3. christopherburton
    Member
    Posted 2 years ago #

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

  4. 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.

  5. christopherburton
    Member
    Posted 2 years ago #

    <?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="http://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="http://doyaldyoung.com">Doyald Young</a></p>

  6. Changing the echo line to:

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

    Should work.

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

  7. christopherburton
    Member
    Posted 2 years ago #

    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; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic