I think your hypothesis is perhaps correct, thanks for that!
I’ll reach out to them to see if they care or not, haha. There was a “Bug report” tag here so I thought maybe a pipeline had been setup for that sort of thing, but no worries.
Thanks!
What great timing! Thanks!
Yeah, though I suppose the implication would be that you want to use the_post_thumbnail() (and other related functions) anyway, if you’re trying to auto-set the featured image, so not a huge downfall.
Although, that said, it doesn’t seem like a lot of work for Elliot to just have a toggle on the image field that sets the image as “featured” (and takes away the ability to set the slug). 🙂
John…..
I’ve been using custom code to do this for years and now your solution seems to obvious! Thank you for posting this.
The is_admin portion works just fine for me so that when editing posts on the back-end it does not redirect to the front-end custom redirect URL.
Yes, that first line looks like a leftover from a previous attempt or something. It can be remove and everything works the same. I’ve done so. Good eye.
If it all works fine now with all plugins updated, it was probably a database issue that was resolved when you re-activated. Just a guess.
I believe you’re right, because I’m using the below code and not having to do any weird math like that.
//Add a row with the user's info as an admin to the Staff repeater field
//There are no rows yet, so we update the value of the repeater field to 1 to make a new row
//The value of the repeater field is simply a number representing the number of existing row
//If ACF ever changes the value of the repeater field in the database, this will need adjusting
if (get_post_meta($post_id, 'choose_tps_members')) {
$existingRows = get_post_meta($post_id, 'choose_tps_members', true);
if (have_rows('choose_tps_members', $post_id)) {
$selectedMembers = array();
while(have_rows('choose_tps_members', $post_id)) {
the_row();
$selectedMembers[] = get_sub_field('choose_member'); //user array
}
}
}
//Add a row to the repeater
update_post_meta($post_id, 'choose_tps_members', $existingRows+1);
//Update repeater row we just created with the Creator's info
$setUser = get_user_by('id',$creator);
$row = array(
'choose_member' => $setUser, //Creator
'make_admin' => array('Admin'), //Check the "make admin" box
);
//Update the repeater row
update_row( 'choose_tps_members', $existingRows+1, $row, $post_id );
//Once all fields validate, we can finally publish it
wp_update_post(array('ID'=>$post_id, 'post_status'=>'publish'));
Hello old thread!
FYI, this is now easier using the update_row function
instead of:
update_sub_field( array( ‘repeaterfieldkey’, $index, ‘subfieldkey’ ), $temp_map), $post_id );
Do this:
$row = array(
'repeater_child_fieldname' => $temp_map,
'repeater_child_fieldname2' => etc....,
);
update_row( 'repeater_name_or_key', $index, $row, $post_id );
Here’s the solution until the feature is added, FYI. Just connecting the posts.
https://support.advancedcustomfields.com/forums/topic/post-titlecontent-labels/
Thank you, that helped. I had the loop syntax wrong.
I would start with a front-end form: https://www.advancedcustomfields.com/resources/create-a-front-end-form/
Thanks James. 🙂
So sorry! Here is the screenshot and json file.
Thanks for throwing a solution out there. Unfortunately, this doesn’t seem to work on front-end forms. Hopefully Elliot finds time to add this in soon.
Just a heads up, Elliot added this as an official field in an update today (yesterday?).
Great thanks!
Excellent news! Can it be confirmed that the data is saved similarly to the previously existing plugin as mentioned above? In other words, if I switched my existing fields to the new ACF fields, will I lose anything?
I’ll do some testing on my end of course, just wondering if that was already thought about.
Thanks!
Hi James, sorry for the delay. I currently have those settings turned off, but when I was encountering the bug I had them turned on, as I mentioned above. So even with the save and load settings turned ON, they are not saving to the post for some reason.
Sure! I’m not using the exact code above, just a similar method. Here is the php code i’m using to display the form as well as the custom function.
The below code works to manually save the taxonomies, but if I remove that portion of the function the taxonomies don’t save.
NOTE: I have the taxonomy field set to NOT save to the post at the moment just in case it interfered with me doing manually. But when troubleshooting, I had it turned on.
Also note, there are fields called “columns” which are reliant on another plugin. They just change the layout of the fields and are not important to the actual content of the form.
On page template:
<div id="new-audition-form" class="hide-submit">
<?php
$new_audition = array(
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'audition',
'post_status' => 'draft',
),
'post_title' => true,
'post_content' => true,
'submit_value' => 'Continue >',
'return' => '%post_url%',
);
acf_form($new_audition);
?>
</div>
Function:
//ACF Front-End Audition Functions
//Redirect to the terms and conditions page on the first post save
function tps_acf_save_audition( $post_id ) {
if (!is_admin()) {
// manually update the audition_type taxonomy field
$term_object = get_term($_POST['acf']['field_5701d3e794a6f'], 'audition_type');
$term_slug = $term_object->slug;
wp_set_object_terms($post_id, $term_slug, 'audition_type');
if (get_post_status($post_id) == 'draft') {
wp_redirect(get_bloginfo('url').'/auditions/terms-and-conditions?auditionid='.$post_id);
exit;
}
}
}
// run after ACF saves the $_POST['acf'] data
add_action('acf/save_post', 'tps_acf_save_audition', 20);
After the user is redirected to the terms and conditions page, they press a button that publishes the post, completing the process.
I know this thread is old, but I’m still running into this problem when saving taxonomies on the front end as well. As noted it seems to happen when using the acf/save_post function to redirect users during a multi-steps post creation process. That seems to be the common denominator at least.
It can indeed be worked around via the part of the function above, but it would be great if anyone on here had any insight into why the taxonomies aren’t saved as they should be based on the ACF settings and if there is a better method of using acf/save_post that will allow ACF to do its magic alongside it.
Thank you for your speedy response! This lead me in the right direction and I think I will be able to figure it out.
EDIT: I accidentally chose my reply as the answer after the page loaded… sorry about that!
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.