logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$8
WPAlchemy: How to output values?

I am using http://www.farinspace.com/wpalchemy-metabox/ and have created my meta boxes and the data is being saved successfully (See below) but I don't know how to output these 'ingredients' on the front end?

Array
(
[docs] => Array
(
[0] => Array
(
[ingredient] => Cheese
)
[1] => Array
(
[ingredient] => Salt
)
)
)


This is my single.php

<?php
global $simple_mb;
$meta = $simple_mb->the_meta();
?>


This is my meta.php

<div class="recipe_ingredients_metabox">

<?php while($mb->have_fields_and_multi('docs')): ?>
<?php $mb->the_group_open(); ?>

<?php $mb->the_field('ingredient'); ?>
<p class="clearfix">
<label>Ingredient</label>
<input class="text" type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/>
<a href="#" class="dodelete button">Remove</a>
</p>

<?php $mb->the_group_close(); ?>
<?php endwhile; ?>

<p style="margin-bottom:15px; padding-top:5px;" class="clearfix"><a href="#" class="docopy-docs button"><?php echo __('Add Ingredient'); ?></a></p>

</div>


This is my functions.php

// Meta WP Alchemy
include_once 'metaboxes/setup.php';

$custom_metabox = $simple_mb = new WPAlchemy_MetaBox(array
(
'id' => '_custom_meta_ingredient',
'title' => 'Recipe Ingredients',
'types' => array('recipe'),
'mode' => WPALCHEMY_MODE_EXTRACT,
'prefix' => '_ingredient_',
'autosave' => TRUE,
'template' => get_stylesheet_directory() . '/metaboxes/ingredients-meta.php',
));

This question has been answered.

Keith Donegan | 07/12/12 at 1:46am Edit

Previous versions of this question: 07/12/12 at 1:48am

(3) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    07/12/12
    2:36am
    Romel Apuya says:


    <?php

    global $simple_mb;

    $meta = $simple_mb->the_value('ingredient');


    echo $meta;
    ?>

    • 07/12/12 6:53am

      Keith Donegan says:

      Thanks Romel but nothing is displayed?

  • avatar
    Last edited:
    07/12/12
    3:28am
    Arnav Joy says:

    to display a value , use this

    $metabox->the_value('name'); // where 'name' is the name of the field..

    in your case it will be

    <?php



    global $simple_mb;

    // set current field, then get value

    $simple_mb->the_field('ingredient');
    $ingredient = $simple_mb->the_value();

    echo $ingredient;

    ?>

    Previous versions of this answer: 07/12/12 at 3:27am | 07/12/12 at 3:28am

    • 07/12/12 6:54am

      Keith Donegan says:

      Your code looked promising but unfortunately it doesn't work :(

  • avatar
    Last edited:
    07/12/12
    1:15pm
    Jatin Soni says:

    Alright I have just finish one gient project using WPAlchemy metabox script. I love it.

    Now as you are using while I believe you want to allow multiple entry for the same field. So in this case you have to get value by using while too.

    So code will be something like this

    while($meta->have_fields('docs')) {
    //all stuffs you want to dsiplay will goes here.
    }



    Also in your code
    <?php

    global $simple_mb;

    $meta = $simple_mb->the_meta();

    ?>


    It may not work and if that is the case than try to use this code

    Change your above code to this
    <?php

    global $simple_mb;

    $simple_mb->the_meta();

    ?>


    and to get value use below code

    while($simple_mb->have_fields('docs')) {
    //all stuffs you want to dsiplay will goes here.
    }


    To get field value use below code

    <?php echo $simple_mb->the_value('ingredient'); ?>


    so your final code should be something like this

    while($simple_mb->have_fields('docs')) {
    //all stuffs you want to dsiplay will goes here.
    echo $simple_mb->the_value('ingredient');
    }



    Previous versions of this answer: 07/12/12 at 1:07pm | 07/12/12 at 1:11pm | 07/12/12 at 1:15pm

This question has expired.



Keith Donegan, Gabriel Reguly voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.