I have now solved this. In the end, it was a combination of using the wrong function and not using the keys as John mentioned. The final line ended up being
update_sub_field(array('field_6064394540d2c', 1, 'field_609d2cad7f0b2'), $number, 'options');
Would it make a difference if I’m using the above code in a page template rather than in the functions.php file?
Hi John
I have tried your solution but it didn’t seem to work. Would there be any obvious reason why not?
Thanks!
I’m only really talking with regards to the ways the fields are layed out. Is there a way in ACF to have fields in a table like in the screenshot I posted?
So essentially I am almost looking to have two fields that can be filled in on each row with three columns.
Hi John,
I thought I included an attachment. I’ll try again.
Never mind I found a way to solve the problem using the taxonomy field in ACF. This can be marked as solved.
I found another post with the solution.
add_action( 'save_post', 'set_featured_image_from_gallery' );
function set_featured_image_from_gallery() {
$has_thumbnail = get_the_post_thumbnail($post->ID);
if ( !$has_thumbnail ) {
$images = get_field('car_gallery', false, false);
$image_id = $images[0];
if ( $image_id ) {
set_post_thumbnail( $post->ID, $image_id );
}
}
}
Thanks. I managed to resolve this myself thanks to your advice.
For anyone who is interested, I just did the following:
function clear_button( $field ) {
echo '<p><a href="#" class="acf-button button button-primary acf-gallery-clear">Clear Images</a></p>';
}
add_action( 'acf/render_field/type=gallery', 'clear_button', 10, 1 );
function my_acf_input_admin_footer() {
?>
<script type="text/javascript">
(function($) {
$('.acf-gallery-clear').click(function() {
$('.acf-gallery-remove').click();
});
})(jQuery);
</script>
<?php
}
add_action('acf/input/admin_footer', 'my_acf_input_admin_footer');
This just clears the images from the gallery rather than deletes them off the website which I may do in the future but for now I just needed a way of starting again with the gallery.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.