• nzde

    (@nzde)


    Hi there

    I’m really keen to understand please what the difference is between:

    <?php echo get_post_meta($post->ID, ‘myImage’, $single=true) ?>

    and

    <?php echo get_post_meta($post->ID, ‘myImage’, true) ?>

    In other words, what difference does adding the “$single” make to the calling of the custom field? In an example I’ve tried, both seem to work. If $single isn’t required, I’ll ditch it from the code.

    Any help much appreciated.

    Kind regards
    Richard

Viewing 2 replies - 1 through 2 (of 2 total)
  • MichaelH

    (@michaelh)

    There really is no difference. I like your 2nd example.

    $single is the default name for the third argument variable of the function.

    Valid values are true, false and possibly 0 & 1..

    There’s no reason you need to write the variable in when calling the function, and i’m not sure the first approach is actually valid (i could be wrong).

    That particular argument sets whether to return the first matched meta value, or multiple (single = true, single item – single = false, multiple items).

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Calling a custom field – what role does $single play please?’ is closed to new replies.