Hi @guymeyer
I’ve done this a million times. Just create the form how you want, and set the name
of each form to the key of the field you want to update. Then when you submit the post, loop through your $_POST and update the fields with update_field()
.
If you have some repeaters and such, you’ll need to use this: update_sub_field
https://www.advancedcustomfields.com/resources/update_sub_field/
Phil
Yeah that works – are you using Checkboxes/Radios instead of a <select>
? Not a big deal either way, but it’ll affect the second part.
Ok, so now, when the page loads, on the Front End, hide the field for counties. There’s probably an id
or class
you can target. so something like $('#counties
).hide()`
Again, I’ve never used the acf_form
so just use your browser’s inspector to sniff it out.
Make a recording of that then we’ll work on showing that County field once your user has selected a State.
Phil
I’ve run into issues where if i’ve named the Flexible Content Field Recipes
and then have a sub block called Recipes
it throws things off.
If the data is there, it may just be easier to loop through it with a foreach
.
Phil
Hey Hey,
1. No, both will be taxonomy options – since you’re using ACF forms to display the form, it needs to know what data to expect. So you’ll basically have 2 of the same fields, but one is for the States and one is for the Counties. Once your user selects the State(s), we’ll use that to populate the data in the Counties <select>, but I wanted you to get comfortable with the first part first.
2. you’re getting ahead of yourself – once you accomplish what I laid out in the previous post, we’ll move on to Part 2.
Phil
Do you have 2 fields set up? One for start and one for end date(s)?
Phil
hi @mische7
no problem, that’s what I’m here for :).
Ok, let’s get you knowledgeable:
1. You’ll need to set up an ACF field for States that allows a user to select multiple values
2. You’ll need to set up an ACF field for Counties that allows a user to select multiple values
3. When the page loads, use JS to hide that Counties field, and then watch for a change on that States <select> and grab the value and console.log
it.
I haven’t used the front end ACF Form, so I’m going in blind, but I think this will get you close.
Once you have the state ID’s (these will be the term ID’s we’ll use in the next step), ping me back.
If you wouldn’t mind, download http://recordit.co/ and use that to show me your progress.
Phil
@enter64 i don’t think it matters how ACF does it – you don’t need to copy the database structure over.
1. Set up the new fields for the custom post types
2. Loop through the old data you have stored
3. Create a new Post and remap that data
If you’re trying to just do a database migration, I think you’re over thinking the problem. Just remap, then delete the old data.
If you’re wanting to do this all via SQL, then I’ll have to defer to someone who has more expertise in that area.
hi @enter64
If you use the methods above, you should be able to figure that out. You just need to loop through the data you have and remap it.
You can use WordPress’ wp_insert_post
to create the new posts and then remap the fields using ACF’s update_field()
functionality.
You’ll need to make sure those fields are set up for the custom post types via the ACF Admin before you can do the remapping.
@louiswalch you only need to sync them if you’re going to pull down the database and make more edits, else you can just leave it alone. I’ll look this over and let you know if I see anything weird ^
Phil
hi @enter64
if you’re just wanting to migrate ACF fields via the ACF Editor, you can just change where the fields are being displayed.
If you’d like, you can use something like http://recordit.co/ to show me what you’re trying to do.
Phil
Hi @tebrown
I would use the acf/save_post
action as found here: https://www.advancedcustomfields.com/resources/using-acf_form-to-create-a-new-post/
You can get the current user via the get_current_user_id
as found here: https://developer.wordpress.org/reference/functions/get_current_user_id/
I hope this helps.
Phil
hi @louiswalch
can you paste the code for the add_local_field_group
?
on a side note, if you’re just wanting to have your fields defined via your theme, instead of the database, i would look into the ACF Local JSON: https://www.advancedcustomfields.com/resources/local-json/
It makes things a bit simpler ^. Just remember to sync the fields on your staging/production apps before pulling down your database.
Phil
hi @enter64
Are you wanting to move the data that you saved to those sliders to your custom post types? Or are you wanting to move the ACF fields you’ve created to the new custom post type?
If the former you could remap the data to the custom post types by using the get_field()
and update_field()
functions. Just loop through the old data, and remap the values to the new custom post type posts.
Phil
hi @dweb
I don’t WP’s oEmbed will allow that: https://codex.wordpress.org/Embeds
If you can edit the front end template, you can just add an ACF field for a url, and put that inside an iframe, or just have a <textarea> box that you output on the front end. Just make sure you select the no formatting option.
Hi @boiledfrog
Are you wanting to display these term names in the admin side of the Visual Composer Element or on the Front End side (or both)?
If it would help, you could use something like http://recordit.co/ to show what you’re trying to do.
Phil
Hi @marcelgro
I haven’t tested this, but we have this function acf_get_local_field_groups
which should return all local field groups.
you can find that function in advanced-custom-fields-pro/includes/local.php
Line 966.
Let me know if that helps.
Phil
Hi @kaito-kaito
I think this is what you’re looking for: https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/
That, combined with the filters on this page: https://www.advancedcustomfields.com/resources/, should get you where you need to go.
Phil
Hi @amu
I’m afraid I don’t understand what it is you’re asking. Would you mind using something like http://recordit.co/ to show me what you’re trying to do?
Phil
Hi @webgleb
I think you need to look over at the Google Map documentation:
https://developers.google.com/maps/documentation/javascript/streetview
ACF just gives you the basic data to construct the map: any further customization would need to be done on the Google Map API’s side.
Phil
Hi @dangdongho1
A lot of what WordPress and ACF does, relies on the ID not changing – that way you’re free to update Titles, Slugs, etc, so I’m not sure what you’re trying to accomplish will work.
If you feel like I’m not understanding you, would you mind using something like http://recordit.co/ to show me what you’re trying to do?
Phil
Hi @goushi
Can you try following step 4 of this article: https://www.advancedcustomfields.com/resources/query-posts-custom-fields/
Update: Since the changed behaviour of esc_sql() in WordPress 4.8.3, it is not easy to use the % character as a placeholder for the following search and replace, instead, we recommend that you use the $ character as shown below.
That may be causing your issue ^
Please let me know if that helps, or if we need to dig a bit deeper.
Phil
Hi @craigivemy
I would start here: https://www.advancedcustomfields.com/resources/acf-fields-post_object-query/
Hook into that bad boy and see what args are being set. I have found, unrelated to ACF, that sometimes I need to force the post_status=publish
for some things to return properly. Maybe start there?
You could also check this guy to see what’s being returned: https://www.advancedcustomfields.com/resources/acf-fields-post_object-result/
Phil
Hi @mische7
If you’re comfortable with doing some fancy javascript, you could listen to the change even on the state <select>
and use it to filter out the options and then display the County <select>
.
Does that make sense?
If you need more control, I would suggest creating your own form, and use wp_insert_post()
and ACF’s update_field()
to submit your data. It’s not very hard and I can walk you through that if you need.
Phil
Hi @bajaczysko
Would you mind using http://recordit.co/ to make a video of what you’re trying to do?
Thank you!
Phil
Hi Gianmaria!
I would look into using the acf/update_value filter found here: https://www.advancedcustomfields.com/resources/acf-update_value/
You can even specify which fields you want to filter using the name={$field_name}
query.
Please let me know if you have any other questions or need anything else clarified.
Phil
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.