Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Using Meta Box plugin unable to display values on home page WordPress

  • SOLVED

I am using this plugin: http://wordpress.org/support/plugin/meta-box

I have followed the instructions (used it before and not had problems) and all of the data is being saved when editing the page but when I try to echo out the values on the home page nothing displays.

Here is the contents of the demo.php file

<?php
/**
* Registering meta boxes
*
* All the definitions of meta boxes are listed below with comments.
* Please read them CAREFULLY.
*
* You also should read the changelog to know what has been changed before updating.
*
* For more information, please visit:
* @link http://www.deluxeblogtips.com/meta-box/
*/

/********************* META BOX DEFINITIONS ***********************/

/**
* Prefix of meta keys (optional)
* Use underscore (_) at the beginning to make keys hidden
* Alt.: You also can make prefix empty to disable it
*/
// Better has an underscore as last sign
$prefix = 'section1_';

global $meta_boxes;

$meta_boxes = array();

// 1st meta box
$meta_boxes[] = array(
// Meta box id, UNIQUE per meta box. Optional since 4.1.5
'id' => 'section1',

// Meta box title - Will appear at the drag and drop handle bar. Required.
'title' => 'Section One',

// Post types, accept custom post types as well - DEFAULT is array('post'). Optional.
'pages' => array( 'page' ),

// Where the meta box appear: normal (default), advanced, side. Optional.
'context' => 'normal',

// Order of meta box: high (default), low. Optional.
'priority' => 'high',

// List of meta fields
'fields' => array(
// TEXT
array(
// Field name - Will be used as label
'name' => 'Title',
// Field ID, i.e. the meta key
'id' => "text",
// Field description (optional)
'desc' => 'Text description',
'type' => 'text',
// Default value (optional)
// CLONES: Add to make the field cloneable (i.e. have multiple value)
),
array(
'name' => 'Content',
'id' => "{$prefix}wysiwyg",
'type' => 'textarea',
'std' => '',

),
array(
'name' => 'Content',
'id' => "{$prefix}wysiwyg2",
'type' => 'textarea',
'std' => '',

),
array(
'name' => 'Content',
'id' => "{$prefix}wysiwyg3",
'type' => 'textarea',
'std' => '',

)

)
);




/********************* META BOX REGISTERING ***********************/

/**
* Register meta boxes
*
* @return void
*/
function section1_register_meta_boxes()
{
// Make sure there's no errors when the plugin is deactivated or during upgrade
if ( !class_exists( 'RW_Meta_Box' ) )
return;

global $meta_boxes;
foreach ( $meta_boxes as $meta_box )
{
new RW_Meta_Box( $meta_box );
}
}
// Hook to 'admin_init' to make sure the meta box class is loaded before
// (in case using the meta box class in another plugin)
// This is also helpful for some conditionals like checking page template, categories, etc.
add_action( 'admin_init', 'section1_register_meta_boxes' );




And I am using this to echo the value of the first text field whose ID is 'text'


<?php echo rwmb_meta( 'text' ); ?>



I've also tried


<?php $meta = get_post_meta( get_the_ID(), 'text', true ); echo $meta; ?>




Nothing gets displayed.

Any help would be appreciated.

Answers (1)

2012-12-06

Dbranes answers:

Hi

does this shows anything:

echo "<pre>";
$customs = get_post_custom(get_the_ID());
$text = (isset($customs['text'][0]))?$customs['text'][0]:"";
var_dump($customs);
echo "<br/>text=".$text;
echo "</pre>";



Dan | gteh comments:

That displays all of the data.

example:

["YOUR_PREFIX_text"]=>
array(1) {
[0]=>
string(25) "WHY GET A MOBILE WEBSITE?"
}


So I see the problem now. "YOUR_PREFIX_" is the default prefix assigned by the plugin. I don't know why the prefix is being added to the ID since I have a) given a new prefix "section1_" and tried removing {$prefix} from the ID.

So.. If I do this:


<?php echo rwmb_meta( 'YOUR_PREFIX_text' ); ?>


then it works.

But why is YOUR_PREFIX being added?


Dbranes comments:

ok, do you have any "section1_text" from the meta dump?


Dbranes comments:

maybe you should try to replace

'id' => "text",

with

'id' => {$prefix}text",

just to see if that works with your new prefix.

ps: here is the function rwmb_meta() defined:

http://plugins.svn.wordpress.org/meta-box/trunk/inc/helpers.php

its based on

$meta = get_post_meta( $post_id, $key, !$args['multiple'] );

just like you tried.