• Resolved kmaier

    (@kmaier)


    if i name a custom field with in a page in the admin: “home_vision”

    and give it a value like: “It is our aggressive pursuit of excellence blah blah blah”

    is there a way i can display that value text to an area on a specific page? Or is that not really what custom fields are for?

    thanks for helping me understand.

    kmaier

Viewing 6 replies - 1 through 6 (of 6 total)
  • You’ll have to add something to your template files, like single.php or index.php

    <?php $vision = get_post_meta($post->ID, ‘home_vision’, true); ?>
    <p><?php echo $vision; ?></p>

    Thread Starter kmaier

    (@kmaier)

    i added it to my home.php but i am not seeing anything. do i need to target a specific ID? i’m using pages.

    Thread Starter kmaier

    (@kmaier)

    got it!!!

    <?php $vision = get_post_meta(43, ‘home_vision’, true); ?>
    <p><?php echo $vision; ?> – hi</p>

    Thanks Jessn!~

    Thread Starter kmaier

    (@kmaier)

    can i have the fields have the same name but generate different values based off whats in the admin?

    <?php if (
    $sideHeader = get_post_meta(2, 'side_header', true)) {
    echo $sideHeader;
    } elseif (
    $sideHeader = get_post_meta(5, 'side_header', true)) {
    echo $sideHeader;
    } elseif (
    $sideHeader = get_post_meta(8, 'side_header', true)) {
    echo $sideHeader;
    } elseif (
    $sideHeader = get_post_meta(10, 'side_header', true)) {
    echo $sideHeader;
    } elseif (
    $sideHeader = get_post_meta(12, 'side_header', true)) {
    echo $sideHeader;
    } else {
    echo '';
    }
    ?>

    whatever i do it only comes up with the first one in the statement on all pages.

    Yes you can. But it looks like your condition might be wrong. Where else is $sideHeader defined?

    From the initial look it seems if you should be doing something like:

    $sideHeader = get_post_meta($post->ID, 'side_header', true);
    if ( !empty($sideHeader) ) echo $sideHeader;
    Thread Starter kmaier

    (@kmaier)

    thanks simplistik that worked just like what i was trying to do for the last hour or so…ha

    really appreciate it

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘understanding custom fields’ is closed to new replies.