• Resolved JesperT

    (@jespert)


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

    Array
    (
        [0] => Array
            (
                [0] => https://www.yahoo.com
                [1] => https://www.internet.com
                [2] => https://www.google.com
                [3] => https://www.cnn.com/
                [4] => https://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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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.

    Thread Starter JesperT

    (@jespert)

    Aha, of course. Thank you very much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_post_meta ads an extra “array”?’ is closed to new replies.