Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Ok, I did something myself, based on a snippet I found in this forum. What I’m doing is:

    – get the gallery shortcode
    – extract the ids
    – save the ids as menu_order for the current images.

    NOTICE: This probably won’t be adequate for you if you want to use the same image in different galleries.

    This one seems to work for me, put it in your functions.php.

    function pmc_gallery_menu_order_fix($id) {
            $regex_pattern = get_shortcode_regex();
            preg_match('/\[gallery[^\]]*\](.*)/', stripslashes($_POST['content']), $regex_matches);
            if (substr($regex_matches[0],1,7) == 'gallery') :
                preg_match('/"([^"]+)"/', $regex_matches[0], $attributes);
                $attributes = $attributes[1];
            endif;
    
            $ids = explode(',', $attributes);
            $images = get_posts( array(
    		'post_parent' => $post->ID,
    		'numberposts' => '-1',
    		'post_status' => 'inherit',
    		'post_type' => 'attachment',
    		'post_mime_type' => 'image',
    		'orderby' => 'menu_order ID',
    		'order' => 'ASC'
    	) );
    	if ( empty($images) ) {
    		// no attachments here
    	} else {
    		foreach ( $images as $attachment_id => $attachment ) {
    			if (in_array($attachment->ID, $ids)) {
    				$update_post = array();
    				$update_post['ID'] = $attachment->ID;
    				$update_post['menu_order'] = array_search($attachment->ID, $ids);
    				wp_update_post( $update_post );
    			};
    		}
    	}
    }
    add_action('pre_post_update', 'pmc_gallery_menu_order_fix');

    Yes, having the same problem here – any ideas so far?

    Thread Starter choeft

    (@choeft)

    Find the moderated code for post-ui-tabs.js here:

    http://pastebin.com/mniEZJeF

Viewing 3 replies - 1 through 3 (of 3 total)