WordPress.org

Ready to get started?Download WordPress

Forums

Types - Custom Fields and Custom Post Types Management
Ordering multiple image field type (7 posts)

  1. LIJE
    Member
    Posted 1 year ago #

    Hi guys,

    I got multiple photos for my products.
    So I have 6 image fields.
    The first one is supposed to be the main and the 5 next are secondary.
    Each time I update my custom post type, the fields get mixed in the front end and I can't get the right first image.

    I'm using :

    $photo = $data['wpcf-photo'];
    for($i=1;$i<=count($photo)-1;$i++) {
    echo '<a class="fancybox" rel="group" href="'.$photo[$i].'"><img src="'.$photo[$i].'" alt="" style="width:140px;height:auto;margin:0 4px;" width="140" /></a>';
    }

    Have you the same issue?
    How can I fixe this?

    Thanks

    http://wordpress.org/extend/plugins/types/

  2. mbigul
    Member
    Plugin Author

    Posted 1 year ago #

    Dear LIJE,

    Please try following code and let me know your feedback.

    global $wp_query;
    $post = $wp_query->post;
    $photos = get_post_meta($post->ID, 'wpcf-photo');
    foreach($photos as $photo){
    echo '<a rel="group" href="'.$photo.'"><img src="'.$photo.'" alt="" style="width:140px;height:auto;margin:0 4px;" width="140" /></a>';
    }
  3. LIJE
    Member
    Posted 1 year ago #

    The full function I used was :

    $args = array( 'post_type' => 'moto', 'posts_per_page' => 100 );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    if(get_post_meta(get_the_ID(), 'wpcf-statut', true) == 'disponible' || get_post_meta(get_the_ID(), 'wpcf-statut', true) == 'reservee') {
    $modele = get_the_title();
    $data = get_post_meta(get_the_ID());
    $photo = $data['wpcf-photo'];
    echo '<tr><td style="width:302px"><a href="'.get_permalink().'"><img src="'.$photo[0].'" alt="'.$modele.'" width="300" style="width:300px;height:auto;" /></a></td>';
    }
    endwhile;

    It's almost the same function.

  4. LIJE
    Member
    Posted 1 year ago #

    Each time I save, the photo get mixed. Weird.

  5. LIJE
    Member
    Posted 12 months ago #

    Well, it works but I have to save my custom post type twice. Any idea why?
    Did you reproduce this issue?

  6. javo01
    Member
    Posted 9 months ago #

    Hi, i have the same problem anyone have the solution?

  7. Srdjan
    Member
    Plugin Author

    Posted 9 months ago #

    Hi, are fields appearing in reverse order or shuffled?

    Can you try using API call?:
    types_field_get_meta_value_repetitive('photo', get_the_ID());
    It should return array of values as ordered on post edit screen.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.