• I inherited a custom website that I need to make some modifications to and one of them is the ability to display the top 10 images from a gallery in a custom post type. I have no problem using the get_children function to loop through and display the images properly. However, despite all I have read. I cannot find a way to sort them for display in the same manner as they are arranged in the back-end. The code for the getting of the image data is below:

    <?php
    	$thumb_ID = get_post_thumbnail_id($pid);
    	$images =& get_children( array (
    		'post_parent' => $pid,
            'post_status' => 'inherit',
    		'post_type' => 'attachment',
    		'post_mime_type' => 'image',
    		'order'=> 'ASC',
    		'orderby' => 'menu_order ID',
    		'exclude' => $thumb_ID,
    	));
    
    	if ( empty($images) ) {
    		// no attachments here
    	} else {
    		//echo '<ul>';
    		$iloop=0;
    		foreach ( $images as $attachment_id => $attachment ) {
    			if($iloop==7) break;
    			echo '<a class="fancybox" rel="group" href="'.wp_get_attachment_url( $attachment_id, 'medium' ).'">'.wp_get_attachment_image( $attachment_id, 'thumbnail').'</a>';
    		    $iloop++;
    		}
    	}
    ?>

    I have tried sorting by “ID’, “menu_order”, and “post__in” but it still does not put the images in the right sequence. The order does change when I add or remove the order_by clause, but it does not properly sequence it. I have looked at the postmeta that is saved where the information apparently comes from and it is just a longtext field. It does get updated when the user moves and image position here is a sample of the text

    {i:0;a:6:{s:2:"id";s:5:"31605";s:3:"url";s:82:"http:/domain.staging.wpengine.com/wp-content/uploads/2016/05/IMG_9112.jpg";s:9:"thumbnail";s:90:"https://domain.staging.wpengine.com/wp-content/uploads/2016/05/IMG_9112-150x150.jpg";s:4:"name";s:8:"IMG_9112";s:7:"caption";s:0:"";s:11:"description";s:0:"";}

    There are no shortcodes being used and the only thing unique about the wp_postmeta record is the meta_key which is “gallery_auction” for all the custom post types. In the record above, the only thing I can see that changes is the first part of the record {i:0;a:6:… where the “i” value gets incremented when the position changes.

    Please help me find a way to do fix this issue?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jkurzner

    (@jkurzner)

    Not sure if this is related or not, but the website also uses the advanced post types order plug-in

    Thread Starter jkurzner

    (@jkurzner)

    Doesn’t appear to be advanced post types issue. Seems more like a problem in how to pull out the value of “i” in the postmeta?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Inherited Problems with Dsiplay of Gallery images in order’ is closed to new replies.