Forums

[resolved] Questionable Meta-Box Formatting (5 posts)

  1. mmaximalist
    Member
    Posted 11 months ago #

    Quick and dirty here we go.

    I am using custom meta-box to show concert data, (i.e. location, venue).

    I have my function.php

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Now I want to incorporate the data from these custom fields onto the post itself, once I have filled them in on the post edit page. Please tell me if this is the proper way to display custom field information on a page.

    <?php if( $venue_info[0] ) : ?>
      <?php echo $venue_info[0] ?>
      <?php endif; ?>

    And of course I put that code into the loop.

    Keep in mind that this works, but what works isn't always what's proper.
    Thank you!

  2. Digital Raindrops
    Member
    Posted 11 months ago #

    That should not work, you should be using get_post_meta(), if it already works then it must already be in your include file?

    Proper post meta would be like:
    Single = get_post_meta($post->ID,'venue_info',true);
    Or $info=get_post_meta($post->ID);
    Then $info[0] $info[1]

    And this is assuming that you also have code to save the values from the meta boxes.

    HTH

    David

  3. mmaximalist
    Member
    Posted 11 months ago #

    Thank you for your help. In your example would you be echoing the $info[0] ?

    My include is a bit large for the forum but here it is. May help.

    [Code moderated as per the Forum Rules. Please use the pastebin]

  4. Digital Raindrops
    Member
    Posted 11 months ago #

    Yes that is correct post meta code so you would echo $info[0] the variable like, Untested:

    <?php
    $info=array();
    $info=get_post_meta($post->ID);
    ?>

    If it is set and has a value do stuff

    <?php if(isset($info[0]) && $info[0]) : ?>
    <h1><?php echo $info[0]; ?></h1>
    <?php endif; ?>

    HTH

    David

  5. mmaximalist
    Member
    Posted 11 months ago #

    Works perfectly. Thank you for your prompt responses.

Reply

You must log in to post.

About this Topic