WordPress.org

Ready to get started?Download WordPress

Forums

Meta Box.. Why Isn't This working? (8 posts)

  1. newyorkcity
    Member
    Posted 2 years ago #

    I followed the tutorial here: http://wp.smashingmagazine.com/2011/10/04/create-custom-post-meta-boxes-wordpress/

    and I ended up with:

    [ Code moderated. For more than 10 lines of code please pastebin.com instead. ]

    but it doesnt post anything in the footer.php.. how do i get this to work?

  2. newyorkcity
    Member
    Posted 2 years ago #

    here is a link to what i ended up with:
    http://pastebin.com/0JR3Rnj7

    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); ?>

    any ideas?

  3. Yojance
    Member
    Posted 2 years ago #

    Hi newyotkcity,

    Please take a quick look at this site.
    http://www.farinspace.com/wpalchemy-metabox/

    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.

  4. s_ha_dum
    Member
    Posted 2 years ago #

    @newyorkcity, if you put var_dump($post->ID) just before your echo do you get the correct post ID?

  5. Digital Raindrops
    Member
    Posted 2 years ago #

    Hi newyorkcity,

    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); ?>

    HTH

    David

  6. newyorkcity
    Member
    Posted 2 years ago #

    @s_ha_dum adding 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

  7. s_ha_dum
    Member
    Posted 2 years ago #

    @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.

  8. Digital Raindrops
    Member
    Posted 2 years ago #

    Hi,
    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!
    Example:

    <?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>

    HTH

    David

Topic Closed

This topic has been closed to new replies.

About this Topic