How should this work / get_post_meta (2 posts)

  1. ancawonka
    Posted 4 years ago #

    Recently (http://core.trac.wordpress.org/changeset/19908), the get_post_meta function was changed to work with just a post ID as a parameter, so that it can be called like this:

    $data = get_post_meta($post_id)

    However, I noticed that it returns every value as an array (so more like get_post_custom). I tried the following:

    $event_meta = get_post_meta( $e->ID , '', true);

    I was expecting that it would return all of my custom fields as single strings, since I'm passing a $single parameter.

    It doesn't quite work that way, though - it's still returning each field as an array.

    Looking at the core code, I can understand why, but I'm wondering if this feature would be useful to others as it is to me.

  2. bcworkz
    Posted 4 years ago #

    The $single parm only works if you pass a $key name, yielding a single result. If you get an array of results, you simply step through the array to do whatever. If one got a list of results instead of an array, one would probably have to explode it, resulting in an array. So I don't see much point, but I will allow that someone may have a use for such a list as is.

Topic Closed

This topic has been closed to new replies.

About this Topic