Home Forums Plugin Support WP User Frontend Pro How can I get the first picture from a field multiple

This topic is: not resolved

This topic contains 7 replies, has 2 voices, and was last updated by  Nayem 3 years, 8 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #73467

    Paris M
    Member
    Post count: 7

    Hello,

    How can I get from a field which have multiple uploads only the first image;

    Thanks!

    #73666

    Nayem
    Moderator
    Post count: 6480

    Hello Paris,

    I am not clear about your question. If you will upload multiple images then all those images will appear on the post. Now, please let me know about your query.

    #73680

    Paris M
    Member
    Post count: 7

    Hello Naymen,

    $images = get_post_meta( $post->ID, 'my_custom_field' );
     
    if ( $images ) {
        foreach ( $images as $attachment_id ) {
            $thumb = wp_get_attachment_image( $attachment_id, 'thumbnail' );
            $full_size = wp_get_attachment_url( $attachment_id );
     
            printf( '<a href="%s">%s</a>', $full_size, $thumb );
        }
    }

    According to this code, upload 10 photos and the question is: how can just pull a photo from the 10 photos?

    Thanks!

    #73707

    Nayem
    Moderator
    Post count: 6480

    Hello,

    Please make me confirm that when do you want to pull the photo? During submit the post or editing the post?

    #73712

    Paris M
    Member
    Post count: 7

    During submit the post display

    #73718

    Nayem
    Moderator
    Post count: 6480
    This reply has been marked as private.
    #73725

    Paris M
    Member
    Post count: 7

    Sorry I did not mean to the submit form, but in display of a product..

    Thanks!

    #73731

    Nayem
    Moderator
    Post count: 6480

    You are posting a WooCommerce product by using Wp user frontend form. So above solution will work.

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘How can I get the first picture from a field multiple’ is closed to new replies.