WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] get_post_meta ads an extra "array"? (3 posts)

  1. JesperT
    Member
    Posted 4 years ago #

    Hello
    When I save an array with get_post_meta I'll get an extra array as this:

    Array
    (
        [0] => Array
            (
                [0] => http://www.yahoo.com
                [1] => http://www.internet.com
                [2] => http://www.google.com
                [3] => http://www.cnn.com/
                [4] => http://www.php.net/
            )
    
    )

    So when I gonna write it out I have to write like this:

    $a = get_post_meta(1,'my_key');
    
    for($i=0;$i<count($a[0]);$i++) {
        echo $a[0][$i].'<br />';
    }

    Why this?

  2. vtxyzzy
    Member
    Posted 4 years ago #

    Does this change things:

    $a = get_post_meta(1,'my_key',TRUE);

    The TRUE says to return a single value (which for you is an array), not an array of all values for that key (an array of arrays). See the Codex here.

  3. JesperT
    Member
    Posted 4 years ago #

    Aha, of course. Thank you very much!

Topic Closed

This topic has been closed to new replies.

About this Topic