Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End When post_meta just ain’t there…

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #28577
    EamonnMac
    Member

    Hey guys,

    I’m working on a parent page that basically consists of nothing more than a big list of its child pages. The title of each child page is given, along with a thumbnail and some basic excerpt details via custom fields and get_post_meta. So far so good. Where I’m falling down is what happens when a custom field is requested and it’s not there, and how to then replace that missing data with default data. I can manage it no probs with the thumbnail, but not for the excerpt. The page isn’t live I’m afraid – but here’s the code I’m using:

    Code:
    $excerptPath = get_post_meta($post->ID, “excerpt”, true);
    if($excerptpath ==””) {
    $excerptpath = “We haven’t included any text here yet, but we hope to have done so shortly!”;
    }

    If the ‘excerpt’ custom field is not present, however, the dummy text doesn’t show. This exact syntax works fine for the thumbnail custom field (replacing it with a fallback img path). Why doesn’t it work in this case?

    Thanks in advance! Any help appreciated.

    #73209
    Chris Coyier
    Keymaster

    Try this:

    Code:
    $excerptPath = get_post_meta($post->ID, “excerpt”, true);
    if($excerptpath) {
    $excerptpath = “We haven’t included any text here yet, but we hope to have done so shortly!”;
    }
    #73211
    EamonnMac
    Member

    No Joy…

    I figure that the code is correct, (‘coz that’s basically what’s in the Codex) but that I’m putting it in the wrong place.

    Here’s the whole page (not too big!):

    Code:

    ID, “intro”, true); ?>

    100, ‘post_type’ =>’page’, ‘post_parent’ => 337, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’ ));

    while (have_posts()) {

    the_post();

    $thumbpath = get_post_meta($post->ID, ‘thumbnail’, true);

    if($thumbpath ==””) {
    $thumbpath = ‘/images/logo/logo_pic_coming_soon_200.gif’;
    }
    ?>

    Again, any help greatly appreciated! :D

    #73533
    EamonnMac
    Member

    Any luck?

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Back End’ is closed to new topics and replies.