Home Forums Add-ons Repeater Field Repeater & order by image id Reply To: Repeater & order by image id

  • ok: i’ve come this far.

    I used the script for Querying the database for repeater sub field values. I deleted the meta_value part because i dont have a meta value, i only have the thumbnails (the value is the path to the thumbnail). So it should view all images used in the sub field thumbnail in the repeater gallery_repeat.

    It shows all images, but in multiple numbers.. (it shows the one repeater 3 times, the other one 5 times, …)

    this is my code: (source: )

    	// get all rows from the postmeta table where the sub_field (type) equals 'type_3'
    	// -
            $rows = $wpdb->get_results($wpdb->prepare( 
                SELECT * 
                FROM wp_postmeta
                WHERE meta_key LIKE %s
                'gallery_repeat_%_thumbnail' // meta_name: $ParentName_$RowNumber_$ChildName
    	// loop through the results
    	if( $rows )
    		foreach( $rows as $row )
    			// for each result, find the 'repeater row number' and use it to load the image sub field!
    			preg_match('_([0-9]+)_', $row->meta_key, $matches);
    			$meta_key = 'gallery_repeat_' . $matches[0] . '_thumbnail'; // $matches[0] contains the row number!
    			//  use get_post_meta to load the image sub field
    			// -
    			$image_id = get_post_meta( $row->post_id, $meta_key, true );
    			// load image src
    			// -
    			$src = wp_get_attachment_image_src( $image_id, 'full' );
    			<div class="item">
    				<img src="<?php echo $src[0]; ?>" />
    				<p class="wp-caption-text">From 
    					<a href="<?php get_permalink( $row->post_id ); ?>">
    						<?php echo get_the_title( $row->post_id ); ?>

    and a screenshot to show how it looks now:

    As you can see, it shows multiple identical images. in my thumbnails theres only one per repeater (all unique).
    It looks like it should be an easy fix, but my knowledge does not reach this far. Would help me out greatly if this was resolved!

    edit: ive noticed that everytime i edit the post, a dublicate of the image is made for some reason…