Forums

[resolved] Please explain these three lines for me (3 posts)

  1. kasperbs
    Member
    Posted 1 year ago #

    Hi I'm rading through a series of tutorials on how to use Wordpress Custom Fields. It is maybe a little bit over my standard, as my PHP knowledge is pretty limited. This is from the website, but could anyone explain a bit more in depth, whats going on so I can google my way to the rest.

    From the website: http://justintadlock.com/archives/2007/10/16/using-wordpress-custom-fields-subtitles

    The CODE
    //

    $subtitle = get_post_meta
    ($post->ID, 'subtitle', $single = true);
    if($subtitle !== '') echo ': ' . $subtitle;

    //

    The explanation from the site:

    "This code pulls your custom field key of “subtitle” out and displays it on whatever pages have a subtitle."

    please elaborate and in PHP language explain what the different things mean.

    Thanks

  2. kasperbs
    Member
    Posted 1 year ago #

    By doing my own research I now understand how to use this.

    I guess it was the if statement that I didn't really knew how to use. And the (not equal to) also confused me a bit.

  3. jord_t
    Member
    Posted 1 year ago #

    Basically the not equal too part of the code checks that the custom field has a value before echoing it.

Topic Closed

This topic has been closed to new replies.

About this Topic