• Resolved Damien

    (@takster)


    Hi.

    I’m trying to pull images from a custom field called images, it’s stored as a comma separated array of multiple images and works almost, but it includes the last , after the last image and screws up by adding an imageless link.

    so as of now it returns

    image1,image2,image3,
    but I’d like
    image1,image2,image3

    note the lack of that final comma. Is it possible to remove it?

    my code:

    <?php
    $images = get_post_meta($post->ID, 'images', true);
    //check that we have a custom field
    if ($images != "")
    {
    // Separate our comma separated list into an array
    $images = explode(",", $images);
    //loop through our new array
    foreach ($images as $image)
    {
    echo '<img src="/wp-content/themes/mytheme/imgr.php?src=' . $image . '&w=600&zc=0&q=90" alt="" />';
     }
    }
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘need help with a comma separated array’ is closed to new replies.