WordPress.org

Ready to get started?Download WordPress

Forums

How should this work / get_post_meta (2 posts)

  1. ancawonka
    Member
    Posted 1 year 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
    Member
    Posted 1 year 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