Oh dear, I’m a dumb!
My problem was that the reference ID was wrong, so would never work. But not to be so ugly, I share my finding.
The code to create a form based on another is:
Front End
<?php
$customtype = get_field('page_customtype');
$idform = get_field('page_idform');
$args = array(
'post_id' => 'newpost_'.$customtype ,
'field_groups' => array( $idform ),
'return' => add_query_arg( 'updated', 'true', "#" ),
);
acf_form( $args );
?>
And the part that makes me proud is how to treat the data to insert without having to have the reference (KeyField) of each field:
functions.php
function my_pre_save_post( $post_id ) {
$customtype = explode('_' , $post_id );
$post = array(
'post_status' => 'Publish',
'post_type' => $customtype[1],
);
$post_id = wp_insert_post( $post );
while (list($key, $value) = each($_POST['acf'])) {
$var = $var . "Key: $key; Value: $value<br />\n";
$namefield = get_field_object($key);
add_post_meta ($post_id, $namefield['name'] , $value, true);
}
}
add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );
Thus a job that took hours (depending on the number of forms) only takes a few minutes.
I hope I can help in any way

K, I was asking because there is quite a difference between how term content (categories) and post content (pages) is saved in ACF.
Basically, all of the acf fields are saves as custom fields in the postmeta table and each field has several values in the database.
The important field would be the post_id field in the database. If you wanted to move all of the field groups from all of the sub pages to the parent page without loosing the data you would need to change all of the references from the child post_id to the parent post_id, You would also need to attach the field groups to the correct page template being used.
The steps involved would be
If you have phpMyAdmin the last part could be accomplished by doing the query
UPDATE wp_postmeta SET post_id = 'PARENT ID' WHERE post_id = 'CHILD ID'
The above assumes that the table uses the standard WP table name and you would insert the actual post_id values where is says PARENT ID and CHILD ID
While this could still be potentially time consuming, it would likely take less time than updating all that data by hand.
Once all the data is updated you can safely delete the child pages.
Make sure you back up your database, just in case.
Thanks for the reply.
The problem is when you edit the main language, it doesn’t propagate on the other languages, because it is a translation and not a duplication.
And when you click “Overwrite” in the other languages, it duplicate all the fields, instead of overwritting them.
And it becomes quite complicated when you’ve got more than 5 languages…
It worked well with ACF (not pro)…
Hi.
I’m not very technical and quite new to WP so please forgive my bad explanation…
Each of my pages is a ‘page’ in WP and I just assign a parent.
My category is actually a country. I have multiple boats in each country. For each boat I assign its parent page as the country to which it belongs. Each boat has series of 4 child pages (always the same for every boat) to which I assign the parent page as the boat.
I hope that makes sense?

okay did it with “str_replace”, just forgot that i used it some months ago, too:
// display a sub field values
echo '<div role="tabpanel" class="tab-pane" id="'.str_replace(' ', '', get_sub_field("tab_titel")).'">'; the_sub_field('tab_inhalt');
echo '</div>';
Hi John
Thanks for getting back to me. You are completely correct – not quite sure why I didn’t realise that in the first place.
It turns out I just needed to add a tag to the link around the images –
data-gallery="gallery-name"
… and that solved my problem.
Thanks again.
Hi there
Thanks for your swift reply.
One image field was just as an example. (I could use the original WP featured image box, but it is really ugly and would require me to make a new post for each image)
I actually need to use the repeater field, repeating an image field. And have each of the images be set to featured.
So say I have one CPT called ‘gallery’, with a ACF ‘gallery images’ (with a repeater field, with image, title, description)
I only want to add one gallery, one post, with as many images as I want inside that one post, and all set to featured image.
Hope this is a little more clear.
If possible I would like to use the gallery field to do the same thing as well.
The problem I see with the code you supplied earlier in this post was that it only uses a set post and field id. And that would constantly change with multiple images needing to be set to featured.
Any help would be great
Just typing it up here and formatting it helped me work it out in my head:
<?php if( have_rows('press_releases') ): ?>
<h2>Press Releases <span class="sprite icon"></span></h2>
<div>
<?php endif; ?>
<?php
$prRows = get_field('press_releases' ); // get all the rows
$first_row = $prRows[0]; // get the first row
$first_row_year = $first_row['year'];
$first_row_pr = $first_row['pr_posts'];
?>
<h3><?php echo $first_row_year; ?></h3>
<?php
if($first_row_pr)
{
foreach($first_row_pr as $pr)
{
echo '<h4><a href="#">' . $pr['heading'] . '</a></h4>';
echo '<p>' . $pr['date'] . '</p>';
}
}
?>

If you’re still looking for help. Not exactly sure what you’re looking for.
Do you want to create a field to select a color and then use that color to change a font color?
Use a Color Picker field. This will allow the selection of a color then.
$color = get_field('my_color_picker_field');
?>
<span style="color: <?php echo $color; ?>;">My Text Here</span>
<?php

Get the link based on the radio field
$resource_link_type = get_sub_field('resource_link_type');
if ($resource_link_type == 'internal') {
$link = get_sub_field('resource_internal_link');
} else {
$link = get_sub_field('resource_external_link');
}
then show the link
<a href="<?php echo $internal_link; ?>">

Or consider using the data-name attribute like so:
.acf-field[data-name="my_field_name"] {
}

Hi Guys
Thanks for the feature request.
I’ll have a think about adding this in, however, for now, please use the following code:
<?php
add_filter('acf/load_field', 'my_load_field');
function my_load_field( $field ) {
// add to class
$field['wrapper']['class'] .= ' ' . $field['name'];
// return
return $field;
}
?>

Actually I’m fine. I’ve been working back through questions here on the forums trying to clean clear up all the unanswered topics. Glad you got you’re problem solved and hopefully the next time you need help you’ll actually get some 🙂

This is not currently possible in ACF. It might be possible to do for someone that wants to do a bit of work. It would require adding custom JavaScript to your field group, adding custom functions and digging in the code for ACF to figure out how to trigger the tabs to toggle.
Can we move this to feature requests? Or should I create a new post?
Beware that this site converts straight quotes to curly quotes.
Thank you Etienne. You got me on the right track. Here is the full code that should go in functions.php:
// Deal with images uploaded from the front-end while allowing ACF to do it’s thing
function my_acf_pre_save_post($post_id) {
if ( !function_exists(‘wp_handle_upload’) ) {
require_once(ABSPATH . ‘wp-admin/includes/file.php’);
}
// Move file to media library
$movefile = wp_handle_upload( $_FILES[‘my_image_upload’], array(‘test_form’ => false) );
// If move was successful, insert WordPress attachment
if ( $movefile && !isset($movefile[‘error’]) ) {
$wp_upload_dir = wp_upload_dir();
$attachment = array(
‘guid’ => $wp_upload_dir[‘url’] . ‘/’ . basename($movefile[‘file’]),
‘post_mime_type’ => $movefile[‘type’],
‘post_title’ => preg_replace( ‘/\.[^.]+$/’, ”, basename($movefile[‘file’]) ),
‘post_content’ => ”,
‘post_status’ => ‘inherit’
);
$attach_id = wp_insert_attachment($attachment, $movefile[‘file’]);
// Assign the file as the featured image
set_post_thumbnail($post_id, $attach_id);
update_field(‘my_image_upload’, $attach_id, $post_id);
}
return $post_id;
}
add_filter(‘acf/pre_save_post’ , ‘my_acf_pre_save_post’);
Thanks for looking. That’s pretty much my conclusion when I was tracing through it. I was hoping that maybe I missed something or that such functionality could be added in a future version of ACF, where you could manipulate a field’s query via Javascript. The relationship field does something similar, but it’s kind of bulky for a repeater.

Hi,
Okay. I took a deep dive into how the ajax works for the post object field and it seems it’s actually calling the acf/fields/post_object/query action for the ajax querying.
http://www.advancedcustomfields.com/resources/acf-fields-post_object-query/
All the logic happens there.
But I’m not sure you can do an add_filter from within an ajax call.. I don’t see a way around this to be honest.

Forgot to mention that it’s a good idea to only include your scripts when needed. Using this filter will help you with that!
http://www.advancedcustomfields.com/resources/acfinputadmin_enqueue_scripts/

Hi @charis
I’m not quite following you. You have a CPT in which you’ve created a single image field? And when saving that you want it to become the featured image?
If so, why not just use the featured image meta box provided by WordPress.
Hi John,
Thanx you helped me a lot. Well, PHP seems quite logical, you say this_is_my_variable and now I play with.
Actually, I changed a small part of your code because some end balise were missing.
I put below my working code.
With my best thanks.
Z
`<?php
$image = get_field(‘image’);
$small_size = ‘cb-480-240’; // (thumbnail, medium, large, full or custom size)
$large_size = ‘full’;
if ($image) {
$small_image = wp_get_attachment_image($image, $small_size);
$large_image = wp_get_attachment_image_src($image, $large_size);
?>
“>
<?php echo $small_image; ?>
<?php
}
?>’

I don’t know anything about the popup in that theme, I’m assuming that you are supposed to link to a larger size image, so you’ll need to get both sizes. Your code should probably look something like this.
$image = get_field('image');
$small_size = 'cb-480-240'; // (thumbnail, medium, large, full or custom size)
$large_size = 'full';
if ($image) {
$small_image = wp_get_attachment_image($image, $small_size);
$large_image = wp_get_attachment_image_src($image, $large_size);
?>
<a class=”cb-lightbox" href="<?php echo $large_image[0]; ?>
<?php echo $small_image; ?>
</a>
<?php
}
Hi there
Interesting post, and nearly what I need, but I can’t understand some things.
when calling the function it passes the variables ’10” and ‘3’.
add_filter(‘acf/update_value/name=sock_images’, ‘acf_set_featured_image’, 10, 3);
being the post id and the post field.
So this would only set the one image from that one post to featured.
I have a custom field called ‘gallery images’ with just one image upload field.
As I add a new gallery image, each image has a new post id. meaning the code you used to set each image as featured would not work.
I am using a gallery plugin that requires all images in custom post types to be featured.
Is this possible at all?
I would like to use the ‘gallery’ field option, or a simple repeater field.
Any help on how to achieve this would be grand.
It would be a nice feature to add in the future, a simple check box when you insert an image field ‘set this image as featured’
Thanks in advance.
Awesome plugin by the way
I need to set each of the images being uploaded to featured, not just one.
Hello John,
thanks for answering. In the last two months since I reported this here, I was in direct contact with the ACF support who was very helpful, even though the problem was not directly connected to ACF.
It was indeed not a problem with ACF itself but a rather obscure server bug that triggered an error with another plugin (IWP Client) which in turn prevented the AJAX call to be completed. Strato, the hoster in question, has since updated/bugfixed their servers.
Best
Freddy
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.