Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm fairly new to PHP/wordpress, and this is actually the first time I haven't been able to answer a question through google! I'm working on getting up to speed with PHP/WP generally, but I can't seem to learn fast enough to keep up with what we need to accomplish already. Please have patience with my ignorance. I'd appreciate any advice, or a push in the right direction.

Basically, I've followed a number of tutorials, and used Jared Datch's CMB script to accomplish a custom post type ('report') that now contains a series of metaboxes, a custom taxonomy, and custom capabilities that allow users of a specific role to access only this post type. Everything looks as it should at the WP back-end (for now)-- data from the boxes is being saved and retrieved property, etc.

http://pastebin.com/Ba82Fzbs

I then created a single-report.php template, followed by a content-report.php template (I am using a twentytwelve child theme), and as I understand it, I need to do something in the content-report.php template to display the information from the custom metaboxes on the individual pages.

I want to display all the metaboxes associated with my custom post type 'report' in a way that will allow further styling/arrangement. So far, I've experimented with do_meta_boxes() and get_post_meta() and I think I just am not understanding the proper usage of either in a very fundamental way, because none of the information displays.

I believe get_post_meta() will give me what I need (the ability to echo data from individual metaboxes so that I can arrange it) and this is how I inserted it into my page template:

    <?php get_post_meta( get_the_ID(), 'date-time');
echo get_post_meta( get_the_ID(), 'date-time'); ?>

Which displays nothing but "array" in that spot when viewed from the front-end. I have had the same problem with my "practice" versions of custom post types and metaboxes, so I'm assuming it's more than a typo-- that I'm missing something very basic.

I would very much appreciate any help with this, and thank you kindly for even reading this far!

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Looking at your code, it appears all meta keys are prefixed with _cmb_. Your start time key is text_datetime_timestamp, so combined with the prefix, you want to fetch:

get_post_meta( get_the_ID(), '_cmb_text_datetime_timestamp', true );

Note the third parameter, which will retrieve a single value if set to true, as it's possible to save multiple values under a single key, which would result in an array of values.

The simplest way to see all of the keys your meta data is saved under, is via get_post_custom_keys:

$custom_field_keys = get_post_custom_keys();
foreach( $custom_field_keys as $key => $value ) {
    echo $key . " => " . $value . "<br />";
}

Put that in the loop and it will tell you the names of all of the keys your meta data is saved under.

share|improve this answer
    
Thank you, I'm trying this out now. –  FriendsCT Feb 15 '13 at 17:33
    
Okay, the get_post_custom_keys will prove very handy-- thank you very much for that. –  FriendsCT Feb 15 '13 at 17:52
    
Thank you so much! This has certainly got me moving in the right direction! –  FriendsCT Feb 15 '13 at 18:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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