#22758 closed defect (bug) (duplicate)
menu_order is 0 for new galleries so no backward compatibility
Reported by: | vickybiswas | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Gallery | Keywords: | |
Focuses: | Cc: |
Description
Shows solved in 22985 and connected tickets but I still see no menu_order update in trunk.
How to reproduce
- Add new post
- Add Media
- Create Gallery
- Upload Files
- Publish Post
The Menu order wont be populated in the DB it will all be 0
also
If you update the gallery re order or do anything it still wont update the same.
This is very needed to maintain the old code to keep functioning seamlessly.
Attachments (1)
Change History (12)
#2
@
12 years ago
Cant update using ajax as its related to post and after alteration using AJAX if the post is not saved it would be incorrect to save the menu_order.
A patch is added for the same
#3
follow-up:
↓ 4
@
12 years ago
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
Since you commented to http://wordpress.org/support/topic/35-rc1-menu_order-not-saved-to-the-database-for-attached-images, could you read the rest of the thread?
As a hidden feature, you can go to the "Uploaded to this post" filter in the media library tab and sort those attachments. menu_order will then save. #22608
#4
in reply to:
↑ 3
@
12 years ago
Replying to nacin:
Since you commented to http://wordpress.org/support/topic/35-rc1-menu_order-not-saved-to-the-database-for-attached-images, could you read the rest of the thread?
As a hidden feature, you can go to the "Uploaded to this post" filter in the media library tab and sort those attachments. menu_order will then save. #22608
Yes but with that feature I am not able to update it once I create
Can you please guide me if I am missing something
#5
follow-up:
↓ 6
@
12 years ago
Insert [gallery] manually into your post. Then rearrange "Uploaded to this post".
There is no way to use the new gallery interface and have it obey menu_order without messing with the [gallery] shortcode in some way. You can use new-style galleries, or you can continue to rearrange "Uploaded to this post" and run queries based on menu order. Can't have both.
#6
in reply to:
↑ 5
@
12 years ago
Replying to nacin:
Insert [gallery] manually into your post. Then rearrange "Uploaded to this post".
There is no way to use the new gallery interface and have it obey menu_order without messing with the [gallery] shortcode in some way. You can use new-style galleries, or you can continue to rearrange "Uploaded to this post" and run queries based on menu order. Can't have both.
The code I am attaching allows editors on my VIP sites to use the new gallery interface and at the same time maintain the menu_order so that our galleries dont break.
The aim is to only maintain the backward compatibility and at the same time use the wonderful new changes.
/** * WP 3.5 doesn't update menu_order for ordering attachments, so this function updates the menu_order so that you can orderby menu_order * @param int $id */ function pmc_gallery_menu_order_fix($id) { global $post; $regex_pattern = get_shortcode_regex(); preg_match ('/'.$regex_pattern.'/s', stripslashes($_POST['content']), $regex_matches); if ( ! $regex_matches ) { return false; } if ($regex_matches[2] == 'gallery') { $attribure_str = str_replace(" ", "&", trim ($regex_matches[3])); $attribure_str = str_replace('"', '', $attribure_str); $attributes = wp_parse_args($attribure_str); } $ids = explode(',', $attributes['ids']); $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 ( $images ) { 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');
#7
@
12 years ago
FYI Vicky's code is a cool way to set menu_order
based off of the ids
shortcode parameter but it's missing this before the $ids
declaration:
if ( empty( $attributes['ids'] ) ) return;
#8
follow-ups:
↓ 9
↓ 10
@
12 years ago
In 3.5, posts can have more than one arbitrary, custom gallery. This is why we don't do exactly this. (And for this code, a second gallery in a post would get missed.)
#9
in reply to:
↑ 8
;
follow-up:
↓ 11
@
12 years ago
Replying to nacin:
In 3.5, posts can have more than one arbitrary, custom gallery. This is why we don't do exactly this. (And for this code, a second gallery in a post would get missed.)
Totally. This is certainly code that belong alongside any custom gallery code in a plugin but not in core.
#10
in reply to:
↑ 8
@
12 years ago
Replying to nacin:
In 3.5, posts can have more than one arbitrary, custom gallery. This is why we don't do exactly this. (And for this code, a second gallery in a post would get missed.)
Nacin I agree and appreciate the second gallery concept however still dont understand how would the second gallery be missed
#11
in reply to:
↑ 9
@
12 years ago
Replying to Viper007Bond:
Replying to nacin:
In 3.5, posts can have more than one arbitrary, custom gallery. This is why we don't do exactly this. (And for this code, a second gallery in a post would get missed.)
Totally. This is certainly code that belong alongside any custom gallery code in a plugin but not in core.
Viper you are correct if it hampers any of the aims of the core but if not it would be good to add for backward compatibility.
The function we are using to handle the same is as below