1

PHP beginner here.

I purchased the Fluent-Framework plugin, which allows me to easily crease Post Types, Meta Boxes, and Option Pages within my theme. I am having trouble echoing the Meta Boxes, however.

Here are the official documents. My Post Type Name: front_page

My HTML:

<button> <pre><?php print_r ( get_post_meta( $post->ID, 'test', true) ); ?></pre> </button>

The HTML Output:

<button> 
    <pre>Array ( [text] => This Is A Test ) </pre> 
</button>

My Meta (Fluent-Framework):

// $meta
$meta = array();

// $meta $args
$meta['text'] = array(
    'dash_icon' => 'list-view',
    'title' =>  __('Section Options', 'fluent'),
    'description' => __('This allows you to change the general settings for your new Section.','fluent'),
    'context' => 'normal',
    'priority' => 'high',
    'caps' => array(),
    'fields' => array(
        'text' => array(
            'type' => 'text',
            'title' => __('Section Style', 'fluent'),
            'sub_title' => __('Set to small, white, grey, dark, darker, black, or parallax one-four.', 'fluent'),
            'required' => true,
            'description' => __('This is just a text field.', 'fluent'),
            'default' => 'dark',
            'option_name' => 'test',
            'seperate' => true
        ),
    ),
);

I need it to return the value of the meta input. Can anyone help me? I'm really lost.

EDIT: Sorry for the 3rd party plugin question... just found out that kind of thing isn't allowed here. :)

Thanks!

6
  • do this. <button><?php echo get_post_meta( $post->ID, 'test', true); ?></button>
    – Robert hue
    Oct 28, 2014 at 17:19
  • This echoes "Array" as a string. Close - at least I'm echoing something! Mind helping me further? :) Oct 28, 2014 at 17:22
  • Try this also. <button><?php echo get_post_meta( $post_id, 'test', true); ?></button>. Where are you using it? Inside or outside the loop. If it returns a array then your post meta contains array.
    – Robert hue
    Oct 28, 2014 at 17:25
  • Returns blank, unfortunately. It is running inside of my loop. Oct 28, 2014 at 17:26
  • Okay, it's an array. use this and add output in your question. <pre><?php print_r ( get_post_meta( $post->ID, 'test', true) ); ?></pre>
    – Robert hue
    Oct 28, 2014 at 17:29

1 Answer 1

4

Okay as you added output of array. You can use the following to get the result. This will print the value of test meta key.

<button><?php $my_meta = get_post_meta( $post->ID, 'test', true ); echo $my_meta["test"]; ?></button>

if your meta key is custom-name then you can get it like this.

<?php $my_meta = get_post_meta( $post->ID, 'custom-name', true ); echo $my_meta["custom-name"]; ?>
8
  • Nope, returns blank. :( I linked the guide but I cannot make sense of it to output what I need. I am following along though, I understand it so far. Oct 28, 2014 at 17:40
  • I updated my answer, please use this echo $my_meta[test];
    – Robert hue
    Oct 28, 2014 at 17:48
  • No echo. I'm trying things and experimenting as you're helping me, but no dice. I really appreciate you helping me, I think we're really close so far. The developer hasn't written me all day, so I'm stuck until we can figure this out. Oct 28, 2014 at 17:56
  • Although it should work but try adding double quote. <button><?php $my_meta = get_post_meta( $post->ID, 'test', true ); echo $my_meta["test"]; ?></button>.
    – Robert hue
    Oct 28, 2014 at 18:00
  • 1
    Oh... I had no idea that was not allowed. Whoops! Well, thank you anyway for taking the time. It truly is appreciated. Cheers! Oct 28, 2014 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.