WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using the jQuery Carousel Gallery and unfortunately it's not working with WP's new v3.5 gallery ordering. When the client drags to rearrange images, those changes are not reflected in the front-end gallery. The plugin is no longer maintained, sadly. So I dove in and can see it's using get_children.

I see this:

$attachments = get_children(
        'post_parent' => $id,
        'post_status' => 'inherit',
        'post_type' => 'attachment',
        'post_mime_type' => 'image',
        'orderby' => 'menu_order'

And this:

$js = array();
foreach ( $attachments as $id => $attachment ) {
    $image = wp_get_attachment_image_src($id, "full");
    // $image = the_attachment_link( $attachment->ID , false );
    $js[] = "{url: '" . $image[0] . "', title: '".addslashes($attachment->post_title)."', caption: '".addslashes(remove_brs($attachment->post_excerpt))."', description: '".addslashes(remove_brs($attachment->post_content))."'}";
$output .= join(",\n", $js);
$output .= "];\n";`

I've seen here and elsewhere that get_posts will adhere to the menu_order orderby parameter, so to try it out I gave this attempt:

$post_img_args = array(
    'post_type' => 'attachment',
    'numberposts' => -1,
    'post_status' =>'any',
    'post_parent' => $post->ID,
    'orderby' => 'menu_order',
    'post_mime_type' => 'image'
$attachments = get_posts($post_img_args);

And in the foreach statement above, I replaced the $image variable with

$image = the_attachment_link( $attachment->ID , false );

This destroyed the gallery on the front end. (A quick note that disabling the plugin and viewing on the front shows the image-ordering just fine, so I do believe it rests with the above code and what it outputs).

Any insight or guidance is appreciated. Thanks.

share|improve this question
Are you sure that the $id of the first statement and the $post->ID of your second statement are the same? – fischi Feb 7 '13 at 18:10
Hi @fischi - I believe they are. $ID is coded before these statements, as $id = intval($id);. – focus97 Feb 12 '13 at 1:20

Following WordPress 3.5, gallery shortcodes now include the image IDs by default. Like this [gallery ids="729,732,731,720"] which also holds the order, so open the plugin file named carousel-gallery-jquery.php and replace this line: (around line 140)

$attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );

with this:

if ( isset($include) && !empty($include) ) {
        $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
        $attachments = array();
        foreach ( $_attachments as $key => $val ) {
                $attachments[$val->ID] = $_attachments[$key];
} elseif ( isset($exclude) && !empty($exclude) ) {
        $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
} else {
        $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );

then at the top of that function on line 121 add this:

if ( ! empty( $attr['ids'] ) ) {
    // 'ids' is explicitly ordered, unless you specify otherwise.
    if ( empty( $attr['orderby'] ) )
            $attr['orderby'] = 'post__in';
    $attr['include'] = $attr['ids'];

and you should be fine :)

share|improve this answer
you rock. Thanks so much. I'm still not getting the sort order on the front to reflect the changes from dragging in WP's gallery. Do I need to remove the if ( isset( $attr['orderby'] ) ) {... which was in place originally? Also, anything to change with the shortcode extract? extract(shortcode_atts(array( 'order' => 'ASC', 'orderby' => 'menu_order', 'id' => $post->ID, 'itemtag' => 'dl', 'icontag' => 'dt', 'captiontag' => 'dd', 'columns' => 3, 'size' => 'thumbnail', ), $attr)); $id = intval($id); – focus97 Feb 8 '13 at 17:31
Nothing more then I posted – Bainternet Feb 8 '13 at 19:56
Anyone else able to provide more insight on this? I have directly replaced $orderby with 'post__in' in the suggested parameters array above, but this does not work either. The images still do not appear in the order of IDs in the WP editor. – focus97 Feb 12 '13 at 1:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.