I followed the tutorial here: http://wp.smashingmagazine.com/2011/10/04/create-custom-post-meta-boxes-wordpress/
and I ended up with:
but it doesnt post anything in the footer.php.. how do i get this to work?
here is a link to what i ended up with:
and this is what i have to print the content of the input in the footer:
<?php echo get_post_meta($post->ID, 'smashing-post-class', true); ?>
Please take a quick look at this site.
I used to hand code all my metaboxes like that tutorial shows you but I haven’t had to write so much code since I found that class which makes this so much easier.
@newyorkcity, if you put
var_dump($post->ID)just before your
echodo you get the correct post ID?
You are using the $post global in the footer?
Is that the post footer or the template footer, inside or outside the loop?
Outside the loop!
<?php if( is_post() ) : ?> <?php global $post; ?> <?php echo get_post_meta($post->ID, 'smashing-post-class', true); ?> <?php endif; ?>
Inside the loop!
<?php echo get_post_meta( get_the_ID() , 'smashing-post-class', true); ?>
var_dump($post->ID)seems to make the footer.php disappear for some reason..
@digital Raindrops Yea I guess it would be outside the loop! I forgot about the loop. Here is the very bottom of my footer.php:
<?php if( is_post() ) : ?> <?php global $post; ?> <?php echo get_post_meta($post->ID, 'smashing-post-class', true); ?> <?php endif; ?> </body> </html>
I checked for the info that should be posted right before the footer but I don’t see anything.. I’m on 3.3 right now since I have been having problems with 3.4 on some other themes
@s_ha_dum adding var_dump($post->ID) seems to make the footer.php disappear for some reason.
That is PHP code so it does need to be done with correct syntax, and needs to be inside opening and closing PHP tags. I sort of assumed that part. Sorry.
<php var_dump($post->ID); ?>
And, yes, it will make a mess of layout but it will also tell you whether or not you have the post ID that you need. Without it, this won’t work.
Try this, it will output only on the footer on a page or single post, it will output all the meta data values in an array tree!
<?php if( is_singular() ) : global $post; $post_meta = array(); $post_meta = get_post_meta( $post->ID, false ); var_dump($post_meta); endif; ?>
Add it inside the page tag!
</div><!-- #page --> <?php wp_footer(); ?> </body> </html>
- The topic ‘Meta Box.. Why Isn't This working?’ is closed to new replies.