Hi Tazintosh,
My code does actually just add meta to attachments, but it does it from the gallery field image with AJAX.
I can’t remove these replies can I?
Update: Solved my issue loading meta.
Was a selector issue in the ajax response.
Ended up using $('[data-id="'+imageID+'"]');
Solved.
If anyone’s interest I’m happy to share the code.
Tazintosh, sounds like you need to add a custom field to the post attachments.
https://code.tutsplus.com/articles/how-to-add-custom-fields-to-attachments–wp-31100
Hey,
I wasn’t following this thread, just stumbled back onto it.
So I’ve implemented an ajax button on gallery images in admin.
It toggles the state from unsold to sold. The state shows on the front end but the problem is loading the state into the admin when returning to edit.
It’s similar to what you’re trying to do. I’m adding post_meta to each image.
Happy to share my code, but i need a method to render the status in the admin if anyone can help with that?
Cheers
√ Notify me of follow-up replies via email
Hi, I’m just checking threads for my own gallery customisation.
While I’m here can i suggest you can get the image ratio and then add classes accordingly as I’ve done.
My php is pretty basic but here’s how I used classes to set column width for my flex grid.
produces this output:
<div class=”image normal 1.5771428571429″>
<div class=”image wide 3.463687150838″>
<div class=”image tall 0.79714285714286″>
<div class=”image very-wide 8.1012658227848″>
if( $images ): ?>
<?php foreach( $images as $image ): ?>
<?php
$ratio_class = 'undefined';
$w = $image['width'];
$h = $image['height'];
$ratio = $w / $h;
switch (true){
case $ratio < 1 :
$ratio_class = "tall $ratio";
break;
case $ratio > 4 :
$ratio_class = "very-wide $ratio";
break;
case $ratio > 2 :
$ratio_class = "wide $ratio";
break;
default:
$ratio_class = "normal $ratio";
}
?>
<div class="image <?php echo $ratio_class; ?>">
I’m actually looking to add another button to the gallery editor thumbs. just like the delete x – but for a sold status on artworks.
Fortunately I’ve got a workaround.
If the client wants to edit a particular gallery…
they just need to:
add to gallery > select all attached (“uploaded to this post”).
done √
Thanks for your suggestions tho
Thanks,
I did try your code, but it didn’t seem to do anything to the existing post attachments on update.
I’m surprised you think this can’t be batch processed. I guess I’ll die trying 😉
Hi John,
Thanks, but I’m unsure how to apply this to my 160 posts automatically.
Ideally I’d run a function once – that checks each post and adds the gallery.
I’ve contacted support as the only part i really need help with the the creation of a new ACF gallery meta_key and meta_value.
Cheers
Hi,
I have a similar query, but i need to create the field.
Can you help?
https://support.advancedcustomfields.com/forums/topic/convert-attachments-to-gallery/#post-44353
Hi John,
Thanks for replying.
I’ll just repeat the critical part:
Convert Attachments to Gallery:
“I have 160 posts from about 5 years ago with existing galleries generated from attachments before wordpress started using gallery item IDs.”
When I say “galleries” I don’t mean WP_galleries because they didn’t exist (using IDs) pre 3.5 They are purely the attachments with common post_parent. They were either uploaded directly to the post using “add media” or “attached” using a utility called file gallery https://wordpress.org/plugins/file-gallery/ which is not user friendly to say the least – hence the need for changing to a better system. I am currently showing either (attachments) or (acf gallery) depending on the post using an if statement.
I can see a few people have created galleries programatically from an array of image IDs (example above). I think all i need help with is generating the _gallery meta_value.
“using update_field() just not sure how to create the field programatically.”
Can you help with that?
Cheers.
This is on the right track
– What I’ve done is just write some PHP code and hooked it to admin_init
– I’m unfamiliar with ACF
http://themehybrid.com/board/topics/automatically-populate-custom-field-with-attached-images
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.