This tutorial shows you how to build a page template that will allow you to create new posts (or custom post type posts) from the front end of your WordPress website using the powerful Advanced Custom Fields Pro (not free) plugin. Some of the code is specific to The Genesis Framework, so you will have modify it to work on non-Genesis themes or child themes.
Part 2 shows you how to edit posts with ACF Pro.
There are lots of other cool plugins like Gravity Forms, Ninja Forms, and Formidable Pro, that allow front end posting, but I prefer using ACF since it also seamlessly integrates any custom fields you may be using as well.
ACF Pro has a really powerful function called acf_form() that gives you the ability to render a form (metabox) on the front end of your site. Then there are filters available that allow you to manipulate the data from the fields and use it to create posts.
There’s a video at the end of this post if you wanna see it in action.
Here’s how we do it.
Create The Metabox(es)
I actually create 2 separate metaboxes, 1 for the default post fields, and another (optionally) for any custom fields I want included in my post. The reason fro 2 metaboxes is simple. I don’t want the fields used for title, content, featured image, categories, and tags to be saving duplicate data as custom fields on a post. I only want that metabox to be there to pass data from the form to the post itself.
Download ACF fields export file
Here’s the metabox for the default fields. Notice that this metabox location is set to a non-existent Options Page (for the reasons explained above).
We are using ACF’s Taxonomy Field Type. This field also works for custom taxonomies, so it can be extremely powerful. Make sure you check the box to “Load value based on the post’s terms and update the post’s terms on save”. This is extremely important. It insures that the category or tag is properly saved when you submit the form. It also makes sure existing categories are loaded correctly when loading the form.
And here’s the metabox for any custom fields. This example just includes a text field in the repeater. Set this location to your post type.
Next, we need the field group ID(s) so our page template knows which metaboxes/field groups to load. This screenshot shows you where in the field group URL to grab the ID. Replace the ID(s) in the page template code with the ID(s) of your field group(s).
Create The Page Template
If you’re attempting this tutorial, you should already comfortable with page templates. Things get a little tricky here.
First off, make sure your ACF field keys are visible in your field group. We’ll need to grab the field keys to use in our template below.
Next, create
Here is our full page template.
Note: A commenter (Al-Mamun Talukder) added a revised snippet for use in a non-Genesis theme. View the code here.
The first function is required for ACF to load all the scripts it needs to work its’ magic. The second function removes the scripts that are only needed when creating a post in the admin.
Our next function is where we load the actual form. The ‘field_groups’ parameter must be updated to include the field group IDs of your newly created field groups. My example is also redirecting to the newly created post URL after submission. If you are submitting to a draft, or something else, you may want to stay on the same page and let ACF show our “Saved!” message via ‘updated_message’ parameter. There’s a lot of flexibility here, so once you get it working feel free to play around with it.
The last 2 functions are our acf/pre_save_post and acf/save_post filters. The pre_save_post function is what creates the actual post using the title and content fields in our form. The save_post form is what takes our image field and uses the attachment ID for the featured image of our new post.
Notice that we don’t need to do anything with our taxonomy fields or our custom(repeater) fields. ACF handles this all for us… awesome!
Create your page
Our code is all ready to go. Just create a page and choose your new page template, and view the page on your site to post. Make sure you are logged in and have posting capabilities.
See it in action here:
Next up… editing posts on the front end!
Hey Mike. This was an awesome post. I myself have been using Gravity Forms for a lot of front end stuff (i.e. Author stuff for my project, PXL Themes). I’m curious about using ACF because I also use it for managing custom fields because GF requires a lot of code to get just right.
Were you able to play around with using more advanced fields, like the repeater or gallery fields, on front-end forms? I’d love to know how things like that worked out for you if so. I’m also interested in knowing if the PayPal feature for ACF works on the front end as well. I’ll probably test these things out sometime soon but I thought I’d ask you in case you were already able to.
Thanks again for the info!
“I’m curious about using ACF because I also use it for managing custom fields AND GF requires a lot of code to get just right.”
Sorry, I’m a grammar nut!
Hey Ren, thanks for checking it out. Make sure you watch the video in the post… I have repeater fields working in this tutorial. Not sure about the ACF paypal feature… is that even a thing? I’ve never heard of any paypal related stuff with ACF.
Hey, Mike. Sounds good. I just read through the article but I’ll check out the video too.
There is a PayPal add-on for ACF but I’ve never used it so I can’t really speak about it too much. I was just curious if maybe you had.
Thanks again!
Wow, with everything I do in ACF I’ve never seen that add-on. All fields should work with acf_form().. but I don’t think it would help for front end posting, right? Actually i’m not sure I understand what that field would do. It’s not like Gravity Forms where a user is submitting to the website… acf_form is for adding content to the site itself.
Do you have an example of how you would use it?
That’s the issue I was running into: what exactly does it do? I haven’t tried it but I plan on at least installing and playing with it to see if I can figure it out. I think it’s just going to output a PayPal button when called. It probably doesn’t go beyond that (i.e. making payment required for submission) so it’s likely that using it with front end posting wouldn’t make sense. If I get some time to test it out soon I’ll update you.
Good Afternoon,
I found this post via Facebook and thought it would help me out in many ways, I followed the steps you have laid out here, however when I go to my page I created on my local machine, I see the Submit button but I don’t see the ACF form as created, I did specify the new template when creating the page.
I don’t see any mention of a shortcode or anything else needed to have form appear on newly created page. I did change the appropriate field names to match my field names (missed that the first time going though the steps)
Ken
Hey Ken, thanks for checking it out. Did you put your correct metabox ID(s) in the code?
‘field_groups’ => array(7,58), // Create post field group ID(s)
7 and 58 are my two metaboxes… you need to put yours in there.
Let me know if that works
Thanks for the quick reply, I headed out to Hockey game so I did not see your reply until now…..
I am not seeing how to get the Field_group metabox id’s your referring do, so I know mine are set to your default…..I am doing some google searches to see how to obtain the values.
Hey Ken, I just updated the post with a screenshot of how to get the field ID. I also added a little comment to the code to let you know where to swap it out. Hope it helps!
That helps! I was just looking at the post again and thought I was losing my mind! I knew that screen shot was not there!
Thanks, I will work on it again in the am!
Ken
By adding the post id, it now works perfectly! Thanks for the updated screenshot, I am in a very bad habit of NOT checking the URL for information, I need to work to fix that.
Thanks agian! I think this may help me out with some sites!
Great post!
Hi, This is great. an you help me a bit. I got problem of Bad request though in my local machine it appear /%post_url% when i clicked the submit button
Awesome, this tutorial is perfect, thanks so much!
I’m big fan of ACF, since a long time, I’ve been using it so much, but never had the opportunity (or needs) to use it front-end.
Now, thanks to you, with this briefly well explained input, a new world of possibilities is opening. I’m shocked. It’s gonna be so cool 😉
Important tip: to override (specify which ones) the field groups when calling acf_form(), I would strongly recommend the use of the ACF field group’s slug instead of the field group’s post id. The acf_form function will understand both post_id as an integer and slug as a string.
For example (11 is a post_id and ‘group_54dfc33796s38’ is a slug), I have put both way in the array for example purpose only, we should use one way or another:
'field_groups' => array( 'group_54dfc33796s38' , 11 )
Using the slug (by opposition to the post_id) will be useful, for instance, if you intend to move groups fields (import/export file) between multiple WordPress installation.
The slug is a unique randomly generated id.
Instead, the post id could be, across different installation, the same for different post depending on your current auto increment (WordPress posts database table); which could lead to the wrong post.
You can found the slug when editing a field group, just select the Screen Options on right-top: check Slug in Show on screen . The slug value should be displayed as the last metabox (at he bottom of the Edit page).
Hi! At last I find the article I need. But I can’t do it. I am not good in php.
1. First I’d like to know where to get to know the field ID, such as field_54dfc94e35ec5, I can’t find it.
2. Here is my code. What is wrong with it, why it don’t work?:
<section id="container" class="”>
<?php
/**
* Deregister the admin styles outputted when using acf_form
*/
add_action( 'wp_print_styles', 'tsm_deregister_admin_styles', 999 );
function tsm_deregister_admin_styles() {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
return;
}
wp_deregister_style( 'wp-admin' );
}
/**
* Add ACF form for front end posting
* @uses Advanced Custom Fields Pro
*/
add_action( 'my_entry_content', 'tsm_do_create_post_form' );
function tsm_do_create_post_form() {
// Bail if not logged in or able to post
if ( ! ( is_user_logged_in()|| current_user_can('publish_posts') ) ) {
echo 'You must be a registered author to post.’;
return;
}
$new_post = array(
‘post_id’ => ‘new’, // Create a new post
// PUT IN YOUR OWN FIELD GROUP ID(s)
‘field_groups’ => array(1195), // Create post field group ID(s)
‘form’ => true,
‘return’ => ‘%post_url%’, // Redirect to new post url
‘html_before_fields’ => ”,
‘html_after_fields’ => ”,
‘submit_value’ => ‘Submit Post’,
‘updated_message’ => ‘Saved!’
);
acf_form( $new_post );
}
/**
* Back-end creation of new candidate post
* @uses Advanced Custom Fields Pro
*/
add_filter(‘acf/pre_save_post’ , ‘tsm_do_pre_save_post’ );
function tsm_do_pre_save_post( $post_id ) {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can(‘publish_posts’) ) ) {
return;
}
// check if this is to be a new post
if( $post_id != ‘new’ ) {
return $post_id;
}
// Create a new post
$post = array(
‘post_type’ => ‘post’, // Your post type ( post, page, custom post type )
‘post_status’ => ‘publish’, // (publish, draft, private, etc.)
‘post_title’ => wp_strip_all_tags($_POST[‘acf’][‘tsm_title’]), // Post Title ACF field key
‘post_content’ => $_POST[‘acf’][‘tsm_content’], // Post Content ACF field key
);
// insert the post
$post_id = wp_insert_post( $post );
// Save the fields to the post
do_action( ‘acf/save_post’ , $post_id );
return $post_id;
}
/**
* Save ACF image field to post Featured Image
* @uses Advanced Custom Fields Pro
*/
add_action( ‘acf/save_post’, ‘tsm_save_image_field_to_featured_image’, 10 );
function tsm_save_image_field_to_featured_image( $post_id ) {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can(‘publish_posts’) ) ) {
return;
}
// Bail early if no ACF data
if( empty($_POST[‘acf’]) ) {
return;
}
// ACF image field key
$image = $_POST[‘acf’][‘mainimage’];
// Bail if image field is empty
if ( empty($image) ) {
return;
}
// Add the value which is the image ID to the _thumbnail_id meta data for the current post
add_post_meta( $post_id, ‘_thumbnail_id’, $image );
}
// acf/update_value/name={$field_name} – filter for a specific field based on it’s key
?>
Hey Natalie, you find the field key here: http://thestizmedia.com/show-field-keys-acf-pro/, that link is in the tutorial as well.
No way to really know why your code isn’t working. Do you have the right field group ID? If you don’t know where to find the field key, that’s going to be the first issue with your code not working.
I’m also not sure where the opening
May be because it is another theme? Actually, they page with form didn’t redirect me to the post that was created. Sad. I do need this decision. But thanks for reply.
If you’re copying my exact code, you definitely need to be using Genesis. If you would like to hire me to implement this on your Genesis site, please fill out the contact form with details. Thanks.
Hello amazing tutorial, the only issue I’m having with it is that the form is always pre-populated with the last post values…any idea?
Thank you
Hmmm, the only way that should happen is if your acf_form() call has a post_id defined in it. This tutorial has ‘new’ as the post ID so it shouldn’t have any data in it.
Are you running any other acf filters? Like load_value or similar?
Complete mystery, can’t find an answer to that weird problem, is like the ‘new’ post_id is already pre-filled with values, when I put ‘new_post’ the fields gets back to empty, but when I put ‘new’ the values of an old post is always there whatever I do…
Where is your form located? In a template? If the form is inside the loop it may be grabbing the post_id from the loop. Is it always showing the same values?
Wanna post your code on snippi.com or other?
My form is located in the /templates folder of my child theme, and it always displaying the same values from the first post I’ve created with my new field group, here’s the code:
http://snippi.com/s/anz9z0s
Hmm.. obviously you need to have your field and group id’s in there.. but it looks correct. Strange.
I’ve renamed all my fields and now it’s working…thank for your time, really appreciated!
Sadly I don’t know where it’s coming from, have disable everything from my function.php that could get in conflict , and I’m using your exact code, except the fields_group id of course, I’ll continue to investigate a little more…thank you.
im not using any theme, rolling my own custom theme. what is the wordpress equivalent to
add_action( 'genesis_entry_content', 'tsm_do_create_post_form' );
Hey Tony. Many other themes don’t require a hook like that. You can just put it right in the template. Possibly between the “while have posts” and the “endwhile”. The function you’re talking about just puts the form in the content area of the page. No trickery happening there.
Hey Mike,
Thanks for posting this…it’s really awesome! I’ve done some really cool things with ACF and I love it, but haven’t done anything with front end editing yet!
Really awesome, can’t wait to try it out.
Tony
Hey Tony! Thanks for stopping by! I’ve only discovered acf_form since ACF Pro came out (was it around before that?).. either way, it’s amazing so far.
Just want to thank you so much for this tutorial. I am yet another fan of ACF, didn’t even know about the acf_form() function, and luckily stumbled onto this post. It is EXACTLY what I needed. You rock.
Thanks Rachelle! I’ve actually been working a lot with acf_form() and I’ve refined it even further since this post… i’ll have to do an update when i get some time.
Thanks for checking it out!
Thanks for this excellent tutorial! I’m close to getting my version working, except i’m seeing the same issue that Seb was seeing. When I first load the form, i’m seeing the previous field values from the last submited form. When I publish the form, it creates it fine, but then if I revisit the form again, the latest fields are still there. I though maybe it was a cacheing issue, but still seeing this in incognito. Any thoughts?
In case it helps anyone in the future, I had this weird instance where the acf fields were being stored int he wp_options table as new_FIELD_NAME such that every time I loaded the acf_form, it would display those values. I cleared the wp_options for all _new_ fields and now it’s working…
Hello,
I cant seem to get this to work within my theme, and this is something ive been looking for.
Ive set my ‘field_groups’ to what my post.php?post=202 is
Ive changed the field’s to the keys within the form and it isnt showing,
What am i doing wrong?
<?php
/**
* Add required acf_form_head() function to head of page
* @uses Advanced Custom Fields Pro
*/
add_action( 'get_header', 'tsm_do_acf_form_head', 1 );
function tsm_do_acf_form_head() {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
return;
}
acf_form_head();
}
/**
* Deregister the admin styles outputted when using acf_form
*/
add_action( 'wp_print_styles', 'tsm_deregister_admin_styles', 999 );
function tsm_deregister_admin_styles() {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
return;
}
wp_deregister_style( 'wp-admin' );
}
/**
* Add ACF form for front end posting
* @uses Advanced Custom Fields Pro
*/
add_action( 'entry_content', 'tsm_do_create_post_form' );
function tsm_do_create_post_form() {
// Bail if not logged in or able to post
if ( ! ( is_user_logged_in()|| current_user_can('publish_posts') ) ) {
echo 'You must be a registered author to post.';
return;
}
$new_post = array(
'post_id' => 'new', // Create a new post
// PUT IN YOUR OWN FIELD GROUP ID(s)
'field_groups' => array(202), // Create post field group ID(s)
'form' => true,
'return' => '%post_url%', // Redirect to new post url
'html_before_fields' => '',
'html_after_fields' => '',
'submit_value' => 'Submit Post',
'updated_message' => 'Saved!'
);
acf_form( $new_post );
}
/**
* Back-end creation of new candidate post
* @uses Advanced Custom Fields Pro
*/
add_filter('acf/pre_save_post' , 'tsm_do_pre_save_post' );
function tsm_do_pre_save_post( $post_id ) {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
return;
}
// check if this is to be a new post
if( $post_id != 'new' ) {
return $post_id;
}
// Create a new post
$post = array(
'post_type' => 'post', // Your post type ( post, page, custom post type )
'post_status' => 'publish', // (publish, draft, private, etc.)
'post_title' => wp_strip_all_tags($_POST['acf']['field_551c760a868e3']), // Post Title ACF field key
'post_content' => $_POST['acf']['field_54dfc94e35ec5'], // Post Content ACF field key
);
// insert the post
$post_id = wp_insert_post( $post );
// Save the fields to the post
do_action( 'acf/save_post' , $post_id );
return $post_id;
}
/**
* Save ACF image field to post Featured Image
* @uses Advanced Custom Fields Pro
*/
add_action( 'acf/save_post', 'tsm_save_image_field_to_featured_image', 10 );
function tsm_save_image_field_to_featured_image( $post_id ) {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
return;
}
// Bail early if no ACF data
if( empty($_POST['acf']) ) {
return;
}
// ACF image field key
$image = $_POST['acf']['field_54dfcd4278d63'];
// Bail if image field is empty
if ( empty($image) ) {
return;
}
// Add the value which is the image ID to the _thumbnail_id meta data for the current post
add_post_meta( $post_id, '_thumbnail_id', $image );
}
// acf/update_value/name={$field_name} - filter for a specific field based on it's key
?>
Hello, i managed a better way, i edited the fields and placed it all in my functions.php and then within my theme i called it by
It works. Beyond perfectly. honestly i cant thank you enough!!
How did you get this working, looks like it didnt display what you wrote “i called it by” and then its blank, did you just grab JiveDig’s code and put in functions.php?
thanks
Mike
Hi,
I am curious..there are any difference in using this example for a simple new post comparing with a new CPT?
If yes, what are the differences?
I need to let the users to insert CPTs from frontend
Thanks a lot!
Nicolas
Hi Nicolas, in my code you will see the acf/pre_save_post filter. In that filter is a setting for ‘post_type’. Change this from ‘post’ to whatever you CPT name is and you’ll be all set.
Hi,
I’m new to Genesis and ACF, I’m following this grat tutorial and it works all fine if i put the template in the Genesis theme directory, but if i use a child theme
/genesis-child/templates
the custom fields won’t show up, I only get the page template with an (Edit) button on it. Am i missing something? Also, which child-theme ar eyou using? And where to find a good one?Thanks a lot!
gio
Doesn’t matter which child theme. After you create the page template you need to select it in the page you want the form to show up in. See the top of this page in the codex https://codex.wordpress.org/Page_Templates
You could use “frontend display” plugin to ACF ver.4
https://wordpress.org/plugins/acf-frontend-display/
and actions processor to create post:
https://wordpress.org/plugins/search.php?q=forms+actions
Video tutorial its here:
https://www.youtube.com/watch?v=75syTKWngbY
Hey Grzegorz, glad to have another bit ACF fan around! Your plugins looks cool. I’ve seen them around but am always leery of 3rd party stuff, especially when I have the flexibility of coding it myself.
I’ll have to play with your plugins soon though. Thanks for stopping by!
Hi Mike,
thanks for this great tutorial!
Is there a way to delete posts from the frontend?
thanks!
Gerd
Hey Gerd, I haven’t looked into that yet.. though I plan too. I would start with getting https://codex.wordpress.org/Function_Reference/wp_delete_post hooked in somewhere. Let me know if you get anything so I can have a head start 😉 Thanks
thanks!
I’ll dig deeper on that!
I think I found a bug in this code.
Wordpress assigns all posts for which a category is not specified a default one (by default “Uncategorized”).
This happens automatically as you publish the post from the backend.
The same does not happen when I submit the post from the front end ACF form, and this causes the new post to be stored without Uncategorized category and (in my case) to be cut off and not display content properly.
I added these lines to acf/pre_save_post filter, before inserting the post:
// If no category is chosen, flag the post as uncategorized
if ((!isset($_POST[‘acf’][‘field_54dfccb977a11’])) || $_POST[‘acf’][‘field_54dfccb977a11’] == “”){
$_POST[‘acf’][‘field_54dfccb977a11’][0] = 1;
}
It seems to work, but is there a better solution?
Interesting.. good catch.
I usually avoid default categories via WP. If you wanted to force a (default) category you could also use wp_set_object_terms.
Thanks for stopping by!
If you want to add ACF form (using 4.4.2 free version), by one click check out this plugin:
https://wordpress.org/plugins/acf-frontend-display/screenshots/
Hi Mike!
This is an awesome, awesome tutorial, thank you for sharing!
I’ve used the textarea field for post content with the Media upload button enabled but, when I upload images to the post, they are getting saved as unattached, not as attached to the post. The same thing happens if I use the ACF gallery addon for uploading images to the post. Is there a workaround for this?
Interesting. I’m not sure if I’ve tested that or not. I wonder if anyone else here can weigh in on it? I’ll have a look next time I’m free.
Wonderful tutorial!
I’m unable to save flexible layout fields contained in repeater fields.
anyone has ever had the same issue?
I’ve done everything right but no title is added to the post. I followed your every step. I got the field ID key like you said. But every time I’m creating a new post it’s left with empty title.
Can you post your code in a gist or snippi.com?
Thanks for your reply. Here’s my code.
Code in template file:
‘new’,
‘field_groups’ => array(866),
‘post_title’ => true,
‘updated_message’ => ‘Post Updated’,
‘new’ => array(
‘post_type’ => ‘recipe’,
‘post_status’ => ‘publish’,
)
));
?>
Code in the functions.php:
‘recipe’,
‘post_status’ => ‘publish’,
‘post_title’ => wp_strip_all_tags($_POST[‘acf’][‘field_55a00fa6ba98f’]),
);
$post_id = wp_insert_post( $post );
return $post_id;
}
?>
Pretty simple. But I wonder why this is not working. This adds post and all the custom fields but title field is left blank.
https://www.dropbox.com/s/7xasl6ts3qv9px5/Field_key.jpg?dl=0 This is the image link that will explain how I get the field key.
I need help urgently. I’m looking forward to hearing from you.
Regards
Efat
Code gets messed up in the previous reply. I’m trying again.
Code in template file:
‘new’,
‘field_groups’ => array(866),
‘post_title’ => true,
‘updated_message’ => ‘Post Updated’,
‘new’ => array(
‘post_type’ => ‘recipe’,
‘post_status’ => ‘publish’,
)
));
?>
Code in the functions.php:
‘recipe’,
‘post_status’ => ‘publish’,
‘post_title’ => wp_strip_all_tags($_POST[‘acf’][‘field_55a00fa6ba98f’]),
);
$post_id = wp_insert_post( $post );
return $post_id;
}
?>
Pretty simple. But I wonder why this is not working. This adds post and all the custom fields but title field is left blank.
https://www.dropbox.com/s/7xasl6ts3qv9px5/Field_key.jpg?dl=0 This is the image link that will explain how I get the field key.
I need help urgently. I’m looking forward to hearing from you.
Regards
Efat
I wonder why the code’s getting all messed up.
You better take a look at the screenshot below:
https://www.dropbox.com/s/3t1jgvx9ng41355/template_code.jpg?dl=0
https://www.dropbox.com/s/m7mbcne0rir6qfn/functions_code.jpg?dl=0
Here’s the snippy.com link for better understanding.
http://snippi.com/s/jcd4zps
Efat, you have post_title set to true, but then you’re trying to define it again in your filter. It doesn’t work that way. Set post_title to false (or don’t put it in at all) if you’re using other fields with it.
If all you need is title and content, you can set post_title and post_content to true and ACF will do the work for you. I typically don’t do this since I often have other fields in use as well, so I do everything manually.
Thanks for your reply. I removed the post_title now but still no title. Here’s the code http://snippi.com/s/diiljs3
I need title and five other custom fields. Here’s the image for other fields. https://www.dropbox.com/s/7xasl6ts3qv9px5/Field_key.jpg?dl=0
I wonder why i can’t get it working. I’m using plugin version 4.2.2
Do I need the pro?
It just can’t grab the title from this line
‘post_title’ => wp_strip_all_tags($_POST[‘acf’][‘field_55a00fa6ba98f’]),
If I try something like
‘post_title’ => ‘Test Title’,
Then it works. So I think it’s all about grabbing the title. I want you to look at the field key if I’m using the right one. Images links are given. Thanks for your time to look at my problem.
Regards
Efat
Check the title of this post 😉 ACF Pro FTW!
Sorry, I didn’t understand what you meant. Would you please explain more what I need to do to get this done?
Regards
Efat
I mean that this post is meant to work with ACF Pro.
My option page have post-setting but i do not have option of “non-existent Options Pag”…
Can you guide… actually i do everything proper but Its not viable.. its working on dashboard only…
This metabox won’t be used on the back end, just set it to something that won’t ever get used.
I bought Pro AFC with all addons…
I spent lot of hrs on this page of FrontEnd…
Steps taken by me:
1) I imported both metboxes (Verified field key) and also set group id (362,359) as per url
2) I created Page template named : page-create-account-for you
Pasted: acf_create_posts_acf_form.php all code to this file (set group id)
last step, I create page from dashboard named as Create Post
and I set attributes (acf_create_posts_acf_form.php) page to this page.
But Displaying nothing when i open page url
I am using twenty thirteen theme
The code I have is meant for a Genesis child theme. It can be modified for a non-Genesis theme, but it won’t work as-is.
I’ve been best your code but when I review template page its found error say :
Fatal error: Call to undefined function genesis()
so how to fix it
please help
best regards..
Hey Peter, as the first paragraph of the post states, this tutorial is written for The Genesis Framework. Most of the code will work on other themes, but you may have to modify it. Naturally genesis() is a function specific to Genesis, so if you’re not running Genesis as the parent theme that function will be undefined.
thanks for replay, I’ve removed the genesis(); line and review the page template nothing displayed of fields group
help me please
thanks..
im using advanced custom post pro for user guest post and all works fine.. but in admin post screen the post submitted been draft its ok, but when I click to publish not publishing or when I click trash not trashed is still on draft..
my function.php code :
add_filter('acf/pre_save_post' , 'my_pre_save_post' );
function my_pre_save_post( $post_id ) {
// bail early if not a new post
if( $post_id !== 'new_post' ) {
return $post_id;
}
// vars
$title = $_POST['fields']['field_123456'];
// Create a new post
$post = array(
'post_status' => 'draft',
'post_type' => 'post',
'post_title' => $title,
);
// insert the post
$post_id = wp_insert_post( $post );
// return the new ID
return $post_id;
}
my archieve.php for acf guest post:
acf_form(array( 'post_id' => 'new_post', 'post_status' => 'draft', 'post_type' => 'post', 'submit_value' => 'submit', 'field_groups' => array( 423 ) ));
can you help me, thank you
I can’t really offer customization help, as this is just a tutorial to get you started. However, your whole bit of code for wp_insert_post() isn’t in a function. It looks like that’s running all the time. That should only be in the original save post function so it only runs when the initial post is submitted.
thanks for replay, but im not found a good answer about searching, my project depends on it, could you try to help me please
I’ve never attempted this on a non-Genesis site, I’m sorry I won’t be of much help for this. I’d just be guessing.
You may want to try a simpler process for front end posting. Caldera Forms was really easy to get going. http://thestizmedia.com/first-try-front-end-submissions-with-caldera-forms-plus-a-review/
Also, Ninja Forms has a really powerful Front End Post/Editor add-on for this as well.
Hi,
thanks for the Tutorial. i managed to get this working without genesis – but am i missing the part in the template where the content from the repeater-part is put into the new post?
i see the repeater-fields in my new post backend – but without content, they are empty. The custom group is set to “post”, i imported your json – but where is the transfer from the front-end-form to the new post in the code?
greetings,
manuel
Hey Manuel, i’m not totally following. Are you seeing the repeater fields in your front end form? You don’t have to ‘process’ anything with them… ACF does it for you. If you have them added in the field group(s) in acf_form() then they should just work.
i just see the fields in the backend – but without the content, that was added to them in the form. they don’t shows in the front end published post, no. Not even if i add values by hand via edit post.
This tutorial doesn’t really get into displaying repeater content on the front-end, that’s regular ACF/post_meta stuff there.
If you’re seeing the repeater fields in your form on the front end, then they should automatically save and show your values in the backend. If that’s not happening, you have another issue somewhere.
ok for anyone having the same issues:
add_filter(‘acf/pre_save_post’ , ‘tsm_do_pre_save_post’);
acf_form_head();
get_header();
the presave filter HAS to be above the other two, otherwise repeater-fields are empty.
dunno why, but this helped finding that solution:
http://support.advancedcustomfields.com/forums/topic/help-with-new-post-from-fontend/
Hey,
Nice tut 😀
But I have 1 issue.
I’m using Basic WP theme Twenty Fifteen, and Im not using Genesis.
I put acf_form( $new_post ); outside Genesis hook
Form is showing but “Save post” button dont work, just nothing happening when clicking it.
My page template code:
http://pastebin.com/L1rTpbSG
Really sorry for spam, you can Delete those comments, Fully Celan WP DB and remake it.
Then Put acf_form_head(); wp_deregister_style( ‘wp-admin’ ); out of functions, and other parts to functions.php.
Now it work like charm 🙂 Thanks for tutorial !!!! <3
Glad you got it to work!
Hello, i have question. It works also with normal ACF version or only with Pro?
I don’t need repeater field, just simple fields with image & text.
I think it’s Pro only, but I haven’t used the free version since Pro came out, so i’m not really sure.
If you apply a unique ID to the form,
‘id’ => ‘acf-church-form’
and I want to filter the Title field in my functions file, how would I target only that church form ID?
Not sure what you are trying to do via the filter, but you don’t need to worry about the form, just filter it based on field key.
acf/load_field – filter for every field
acf/load_field/type={$field_type} – filter for a specific field based on it’s type
acf/load_field/name={$field_name} – filter for a specific field based on it’s name
acf/load_field/key={$field_key} – filter for a specific field based on it’s name
via http://www.advancedcustomfields.com/resources/acfload_field/
So the form would create a “pending” new post into the ‘church’ CPT. The field I want to filter is the post title, and not a acf field, changing “Title” to “Church Name”. But I have other acf forms for event submission and that filter affects their post titles too.
In the parameters of acf_form, the first option is ‘id’, and I figure I could target it that way.
I ended up using an is_page() check to keep the filter to that one form, but you may have more than one form on a page and it would be nice to target just that form by ID.
I guess I could do an, if has key, in the form. I was just curious if you had come across this.
By the way, love your part2 to this! I really had been wanting to make what you did into a plugin but never found the time. Thanks.
Are you using the same acf metabox/form on different pages? If not, then the title field key should be used in the filter. There probably is a way to check form ID, but I haven’t done it. I use CMB2 now for more complex stuff, and check the metabox ID that way.
Just a sidenote, Caldera Forms with the Custom Fields add-on is super easy for front end posting and may get you where you wanna go much faster. I have a post here about posting testimonials with Caldera Forms.
Hello,
Thanks for your tutorial. I use it for thumbnail part with ACF5 pro. I’ve a question because when I upload image with image custom fields, image is not resize and crop like classic thumbnail. How I can add this part on your function ?
Thanks a lot !
Image is not resized where? Any image uploaded via the WP uploader (including ACF fields) should get cropped by all registered image sizes. Front end display is another story, your theme/plugins/code/etc tells WordPress which image to display.
Yes I know that. But When I add image on front end form, image are not resize (I’m checking images in my upload folder), there is only the base image.
Thanks for this! It’s super-helpful and adds to the explanation of acf_form() on the actual ACF site.
Hi JiveDig,
i put the code inside my theme (generate press) but i can’t see the form in front end; i modify this line :
‘field_groups’ => array(95,92), // Create post field group ID(s)
with this :
…post.php?post=95&action=edit –> Post Default Fields
…post.php?post=92&action=edit -> Post Custom Fields
Could you help me please ?
Kind regards,
Alessio
You should replace the 95 and 92 with your actual custom field group ID’s (or keys).
Now i see the forms but cannot save the post, any idea ?
Thanks.
Hi JiveDig,
Excuse me to post a message in your blog, but impossible to have an answer from the official ACF support.
http://support.advancedcustomfields.com/forums/topic/front-end-form-how-to-change-post_title-and-post_content-properties/
If it can help someone…
1 – I use the ACF PRO 5.3.2.2 so with this version, I use the 2 new acf_form() parameters to save the post title and post content :
acf_form(array(
….
‘post_title’ => true,
‘post_content’ => true,
…..
));
ok, it works but how change the properties of these fields (maxlenght, required, disabled….)
As you can see in my ACF ticket, I try different solutions but my modifications are not considered during the submit.
So, how can we change the post_title and post_content properties with ACF PRO 5.3.2.2 ?
I try your solution, with “acf/pre_save_post” but it doesn’t work for me, title and content are empty after submit. 🙁
2 – Another question: is it possible to put a custom form field between post_title field ans post_content field ?
Thanks a lot per advance.
Claw
Hello JiveDig,
is it possible to put this code into the functions.php and then use a filter CONTENT on a special page ID?
Cheers,
Denis
Sure. I hook in via the Genesis-only genesis_entry_content hook, but you can certainly ad it via the content filter for other themes. Just check is_page($page_id_or_slug) in your filter.
Hey JiveDig,
I tried this, but nothing happens. The Post is not stored.
function myPostFunction ( ) {
if (is_page( 4339 )) {
/* Mein ACF Form auf der Page */
/**
* Add required acf_form_head() function to head of page
* @uses Advanced Custom Fields Pro
*/
add_action( 'get_header', 'tsm_do_acf_form_head', 1 );
function tsm_do_acf_form_head() {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
return;
}
acf_form_head();
}
/**
* Deregister the admin styles outputted when using acf_form
*/
add_action( 'wp_print_styles', 'tsm_deregister_admin_styles', 999 );
function tsm_deregister_admin_styles() {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
return;
}
wp_deregister_style( 'wp-admin' );
}
// Bail if not logged in or able to post
if ( ! ( is_user_logged_in()|| current_user_can('publish_posts') ) ) {
echo 'You must be a registered author to post.';
return;
}
$new_post = array(
'post_id' => 'newt', // Create a new post
// PUT IN YOUR OWN FIELD GROUP ID(s)
'field_groups' => array(46,43), // Create post field group ID(s)
'form' => true,
'return' => '%post_url%', // Redirect to new post url
'html_before_fields' => '',
'html_after_fields' => '',
'submit_value' => 'Submit Post',
'updated_message' => 'Saved!'
);
acf_form( $new_post );
/**
* Back-end creation of new candidate post
* @uses Advanced Custom Fields Pro
*/
add_filter('acf/pre_save_post' , 'tsm_do_pre_save_post' );
function tsm_do_pre_save_post( $post_id ) {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
return;
}
// check if this is to be a new post
if( $post_id != 'new' ) {
return $post_id;
}
// Create a new post
$post = array(
'post_type' => 'post', // Your post type ( post, page, custom post type )
'post_status' => 'publish', // (publish, draft, private, etc.)
'post_title' => wp_strip_all_tags($_POST['acf']['field_54dfc93e35ec4']), // Post Title ACF field key
'post_content' => $_POST['acf']['field_54dfc94e35ec5'], // Post Content ACF field key
);
// insert the post
$post_id = wp_insert_post( $post );
// Save the fields to the post
do_action( 'acf/save_post' , $post_id );
return $post_id;
}
/**
* Save ACF image field to post Featured Image
* @uses Advanced Custom Fields Pro
*/
add_action( 'acf/save_post', 'tsm_save_image_field_to_featured_image', 10 );
function tsm_save_image_field_to_featured_image( $post_id ) {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
return;
}
// Bail early if no ACF data
if( empty($_POST['acf']) ) {
return;
}
// ACF image field key
$image = $_POST['acf']['field_54dfcd4278d63'];
// Bail if image field is empty
if ( empty($image) ) {
return;
}
// Add the value which is the image ID to the _thumbnail_id meta data for the current post
add_post_meta( $post_id, '_thumbnail_id', $image );
}
// acf/update_value/name={$field_name} - filter for a specific field based on it's key
} // END IF PAGE
} // END FUNCTION
add_filter ( 'the_content', 'myPostFunction' );
Doesn’t look like you are using the_content filter correctly. Unfortunately that’s a bit more detailed than i’m able to help with via comments, but check out Pippin’s awesome post for a head start.
Hi
I am looking at providing this functionality but checking the official ACF Documentation and your tutorial, there are quite some differences. Your’s looks much more complicated!!
With your method, if the user updated the Title, then would the slug also update?
I’m testing at the moment with the basic ACF Documentation and it does not.
Also can I ask why you created those extra fields for the title and content when you could have used these:
/* (boolean) Whether or not to show the post title text field. Defaults to false */
'post_title' => false,
/* (boolean) Whether or not to show the post content editor field. Defaults to false */
'post_content' => false,
(http://www.advancedcustomfields.com/resources/acf_form/)
Many thanks again
Hi Huw, yes my version is definitely more complicated. When I used the default ACF title/content fields, I had some issues adding other field groups and/or fields. There was some other stuff that limited the flexibility of the form so I opted to manually build it.
Thank you for the reply.
If the user updated the title (if I used you’re page template code), would that also update the slug?
I am currently building a membership style site, where the user signs up and posts to a custom post type; but upon Submitting the post, it redirects to PayPal for payment before actually publishing the post.
Do you know if this would be achievable by modifying your template/s ?
Many Thanks
Thanx so much for this tutorial! Ive been trying to get my head around to add new wordpress users and your dummy field group trick saved my life. Clear and concise tut!!
Glad it helped you out!
Where add the id?
in your template is array(7,58) my id is 2475
its that right? > array(2475)
Yep 😉
And how i add the template to a page?
have save the acf_create_posts_acf_form.php to my theme directory and now?
Hi James, you choose the template the same way you would choose any other template… via the Page Attributes metabox. See here: https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/
is the tsm_ wordpress standart or from your theme?
That is just a prefix to avoid potential classes with other theme/plugin hooks. TSM = The Stiz Media. It could be anything.
Those of you who are not able to work it on a non-genesis theme, here is the solution.
http://pastebin.com/P08kJzUW
Hope it helps 🙂
Great tutorial by the way.
Regards
Much thanks Al-Mamun! I updated the post with a link to your code (and your website). I’m sure many people will be happy for this. Thanks again!
Hey Mamun thanks for the code! Do you also have a non-genesis code for editing the posts?
Love this tutorial – thanks! However, I’m having a bit of an issue and was wondering if you might have an off-the-cuff answer. The template and form seem to work, but when I click “Submit” the Title and content appear to be lost – and the post doesn’t publish. It’s saved as a draft…which I can’t delete. In the back end, if I try to delete these drafts that I’ve created with it, a message tells me they’ve been moved to the trash but they”re still there as drafts?!?
…I should add, I’m using your exact code except I’ve changed to reflect my Field keys and Field Group ID (only using 1 group). Using the Genesis Outreach theme.
Hey Kip. Make sure the `if( $post_id != ‘new_post’ ) {` line matches the post ID in your acf_form array. It sounds like the fields aren’t getting passed that check.
Sorry for the bother. I’ve tinkered around and don’t seem to see what the trouble is. Here’s where I am at the moment:
<?php
/**
* Template Name: Create Post
*
* @author Mike Hemberger
* @link http://thestizmedia.com/front-end-posting-with-acf-pro/
* @uses Advanced Custom Fields Pro
*/
/**
* Add required acf_form_head() function to head of page
* @uses Advanced Custom Fields Pro
*/
add_action( 'get_header', 'tsm_do_acf_form_head', 1 );
function tsm_do_acf_form_head() {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
return;
}
acf_form_head();
}
/**
* Deregister the admin styles outputted when using acf_form
*/
add_action( 'wp_print_styles', 'tsm_deregister_admin_styles', 999 );
function tsm_deregister_admin_styles() {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
return;
}
wp_deregister_style( 'wp-admin' );
}
/**
* Add ACF form for front end posting
* @uses Advanced Custom Fields Pro
*/
add_action( 'genesis_entry_content', 'tsm_do_create_post_form' );
function tsm_do_create_post_form() {
// Bail if not logged in or able to post
if ( ! ( is_user_logged_in()|| current_user_can('publish_posts') ) ) {
echo 'You must be a registered author to post.’;
return;
}
$new_post = array(
‘post_id’ => ‘new_post’, // Create a new post
// PUT IN YOUR OWN FIELD GROUP ID(s)
‘field_groups’ => array(182), // Create post field group ID(s)
‘form’ => true,
‘return’ => ‘%post_url%’, // Redirect to new post url
‘html_before_fields’ => ”,
‘html_after_fields’ => ”,
‘submit_value’ => ‘Submit Post’,
‘updated_message’ => ‘Saved!’
);
acf_form( $new_post );
}
/**
* Back-end creation of new candidate post
* @uses Advanced Custom Fields Pro
*/
add_filter(‘acf/pre_save_post’ , ‘tsm_do_pre_save_post’ );
function tsm_do_pre_save_post( $post_id ) {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can(‘publish_posts’) ) ) {
return;
}
// check if this is to be a new post
if( $post_id != ‘new_post’ ) {
return $post_id;
}
// Create a new post
$post = array(
‘post_type’ => ‘post’, // Your post type ( post, page, custom post type )
‘post_status’ => ‘publish’, // (publish, draft, private, etc.)
‘post_title’ => wp_strip_all_tags($_POST[‘acf’][‘field_5713bc078462f’]), // Post Title ACF field key
‘post_content’ => $_POST[‘acf’][‘field_5713bc2a84630’], // Post Content ACF field key
);
// insert the post
$post_id = wp_insert_post( $post );
// Save the fields to the post
do_action( ‘acf/save_post’ , $post_id );
return $post_id;
}
/**
* Save ACF image field to post Featured Image
* @uses Advanced Custom Fields Pro
*/
add_action( ‘acf/save_post’, ‘tsm_save_image_field_to_featured_image’, 10 );
function tsm_save_image_field_to_featured_image( $post_id ) {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can(‘publish_posts’) ) ) {
return;
}
// Bail early if no ACF data
if( empty($_POST[‘acf’]) ) {
return;
}
// ACF image field key
$image = $_POST[‘acf’][‘field_5713bca884633’];
// Bail if image field is empty
if ( empty($image) ) {
return;
}
// Add the value which is the image ID to the _thumbnail_id meta data for the current post
add_post_meta( $post_id, ‘_thumbnail_id’, $image );
}
// acf/update_value/name={$field_name} – filter for a specific field based on it’s key
//* Run the Genesis loop
genesis();
I don’t see what the problem is, unfortunately. It looks right to me. Do you have other custom fields or are you just using Title/Content/Image? ACF has parameters to automatically create title/content fields… in the acf_form arguments array just add ‘post_title’ => true, and ‘post_content’ => true,.
Getting somewhere…
1.) I don’t have any other custom fields in play. This is a fresh install for a site I’m building for a local orphanage.
2.) I added what you said to the array, and a couple things changed:
I now have TWO sets of fields to complete when I open the page template. Only one of them is functional – I filled them both out with unique info, and the first set of fields works; the second doesn’t. Although it is saving the post with submission, it’s still in draft rather than actually publishing it.
I don’t want to bother you much more. If I can’t make this work it isn’t a world-ending problem; I was just trying to allow the ladies who will be using this site to post from the front end. They don’t have a huge amount of technical interest, nor available time with 80 kids running around 🙂
Kip… no prob. It’s probably something small that’s tripping it up.
Honestly, if all you need is basic front end posting, you’re probably better off using Caldera/Gravity/Ninja/Formidable Forms. Caldera will do it for free, I have a couple posts here about it.
Exactly the same ‘thing’ here, just added the two lines:
$new_post = array(
'post_id' => 'new_post', // Create a new post
// PUT IN YOUR OWN FIELD GROUP ID(s)
'field_groups' => array(1044,1041), // Create post field group ID(s)
'form' => true,
'post_title' => true,
'post_content' => true,
'return' => '%post_url%', // Redirect to new post url
'html_before_fields' => '',
'html_after_fields' => '',
'submit_value' => 'Verstuur bericht',
'updated_message' => 'Verstuurd!'
);
acf_form( $new_post );
And inserted all the right group and field ‘stuff’ to make it work. But also here two times the title and content block in the front-end form and after submitting it ‘end-up’ like a draft….
Any ideas?
Kind Regards,
Peter Luit
Do your custom field groups also have a title/content field? Try to remove the field_groups line and just use ACF’s title/content fields to see if it is working correctly.
I did remove this: ‘field_groups’ => array(1044,1041), // Create post field group ID(s)
Yes then only one title/content appears, but taxonomies are gone. And the post creates well in ‘draft’.
I would like to add that the first title field is (in the inspector):
input#acf-post_post_title
The second shown title field is:
input#acf-field_54dfc93e35ec4
By adding the lines:
‘post_title’ => true,
‘post_content’ => true,
the form is show twice only for title and content. What do I do wrong?
Peter
Your custom field groups also have a title and content field. Either remove them from the field group, or set those to false above.
I downloaded your ACF fieldsettings. I did not make any changes.
Do I understand you right that I should remove the fields ‘title’ and ‘content’ from the group ‘post default fields’?
OK, that worked. Final thing:
‘post_status’ => ‘publish’,
But after submitting the post form the fornt-end, the post becomes a ‘draft’.
Peter
This is just what I needed!!! Thanks!
Wanted to share an update.
With ACF version 5.5.0 the pre_save_post function is deprecated and replaced by adding options to the “new_post” option for the acf_form function parameter.
See: https://www.advancedcustomfields.com/resources/acf-pre_save_post/ for details.
You can replace the tsm_do_pre_save_post function with adding the following to the $new_post array in the tsm_do_create_post_form function :
‘new_post’ => array(
‘post_type’ => ‘project’,
‘post_status’ => ‘publish’,
),
Thanks John! I’ve used the “new_post” parameter before, but sometimes a separate filter is easier to separate the logic IMO.
Can you point me to where “pre_save_post” has been deprecated? It still looks like a valid option at this point.
This is fantastc I was using custom fields in wc-vendor but for some reason its not saving my fields I was using grabity forms but was wanting to change to acf front end ask makes for a neater solution do you have any tips of how to save to a post type of wc vender woocomerces offical vendor plugin
Hey David, thanks for checking it out. To save WooCommerce simple products you just need to change the post type to ‘product’. It gets quite a bit more complex if you need variable products and lots of other product meta. It’s doable, but much more involved.
#JiveDig thanks! You just put turned on light for one of my upcoming project and ACF can surely help me. I need to build a custom user account dashboard in front end of the site. Where contributors can post to custom post type and subcribers can contact to them directly. I believe ACF can help me to do so. Am I correct? If you like to give me any tips or suggestions, you are welcome.
Totally possible. acf_form() and acf/load_value acf/update_value filters can do some amazing things. Have fun!
Dear JiveDig, is it also possible to have form steps? I mean I have a form which requires 6 steps (Each page is one step. Click to go next page) data entry. Its a custom post type. If I call acf_form(), it shows all fields together inside a single page just like WP admin (create new custom post). Can you help me to achieve this?
I’m sure it could work with some custom code. The full form would still technically be loaded, but it would show/hide sections of fields via JS. You’d have to add previous next links and show/hide the fields you want on click.
Hello excellent guide.
I come straight to the point. I’m using a different theme for the genesis called ItaliStrap starter fears.
I am having trouble with the creation of a form in a front end for the user metadata management.
every time I try to send the form to me is that this error.
“Do you really want to do this?
Try again”
I created three files. user_page.php-header, and footer-page_user.php user_page.php
You can see a piece of code here.
http://pastebin.com/ySruhtmn
I can not understand why it seems to have done everything right. I read a lot about it but I can not figure out what to do
Hi,
I have a two CPT connected to each other with Post to Post plugin
1- Project (title, description and image)
2- Project Photos (full post support)
It works fine in the backend, but I need a frontend form for users to add their projects. What I have come across every frontend form plugin only allows from to attach single post type.
I need two/multi-step form first user add the project and next he will add the project photos. How would I achieve it. Any thoughts or referring material would be highly appreciated.
Multistep may have to be done with some basic jQuery show/hide, like a tabbed-esque interface. As for the Posts 2 Posts part, maybe my P2P Restful Connect plugin will help there. It will definitely take some code, but should be doable.
Awesome tutorial…this definitely came in handy and was very helpful (especially the snippet of code to make it work in a non-Genesis theme). However, it does not appear as though conditional settings work. I have a select field and depending on which option is selected, another field (repeater) is supposed to show (or not). It shows all the time using the front end form. Definitely frustrating.
Hi.
When i click submit all fields are saved but not post title, any idea ? My fields key are ok.
Thanks.
Hi and thank you for this tutorial!
Its exactly what I need, but unfortunately I was not able to make it run like expected.
I am using Genesis and I am using ACF PRO.
It seems that the title and content is not stored. In addition to that the repeater field is just one edit field and one is not able to add a line. I can see in posts that the post is not in the state ‘published’ instead its a draft.
first I tried it like in this tutorial for posts and just changed the field ids.
then I changed the post type to a custom post type. but i get the same problem and the post created is ‘post’ and not my custom post type.
Can anybody advise what to check/look for or anybody got the same problem?
Thank you very much!
Hello Mike,
great tutorial.
Is there also a way to create a dashboar or list of the posts, the current user allready created? So that the user does not need to go to the backend. if he likes to see his Posts and maybe delete or edit them?
Cheers,
Denis
I am using ACF pro and create Google map field in ACF. I can see that field in back-end of custom post and on front end, but I am trying to add this Google map field into my Custom Form on Front-end. Same like you are doing but need Google Map. How can I do this. I am stuck here.
This should work as expected. If you’re not seeing a map you probably need to add an API key. See this ACF doc.
Hi, I have a problem implementing this. Everything seems fine, but when i click the submit button, there are Two posts created with same details of submission. Can you let me know what i am doing wrong or guide me where the issue might be..
There could be a few things happening there, you’d have to debug step by step to figure out what’s causing your issue.
Great article,
I do have some silly questions, but I won’t learn if I don’t ask, right.
So I have several fields I am using, so do I need to add those fields into the new post array? Example, if I am adding a phone number would I add:
‘post_phone’ => $_POST[‘acf’][‘field_key]
Or will I need to add something else or is there more to this than what I am thinking?
Thanks,
Brad
Those fields would probably just be post_meta, so you’d have to handle/save it some way to the meta. `wp_insert_post` has a `meta_input` parameter that you can look into. It sounds like you should read up on how the WP database data is stored, to get a good understanding of that before you try to manipulate that data with code. Thanks for stopping by!
Hi, JiveDig!
Excellent tutorial. I was able to put my ACF form on the front frontend, as I had been wanting for some time. I am very happy. Great tutorial, congratulations! My next step is to follow the tutorial of editing the post in the frontend. 🙂
However, I have a problem, after completing the form and clicking on “Publish” it is as if it did not save, it will clear the form, you know? And it does not rise to my post list. What can I be doing wrong?
Could you help me please?
Thank you in advance!
There are so many factors involved in this tut that it’s hard to really narrow it down. You’ll have to debug step by step in the process to find the culprit. Good luck!
Thank you for your sharing this is the tutorial Ive been looking for good ob keep it up sir
Hey guys, great tutorial. I had to change the priority of my acf/pre_save_post filter to 1 to avoid it creating duplicate posts when I created a new one.
add_filter(‘acf/pre_save_post’ , ‘tsm_do_pre_save_post’, 1, 1 );
Nice tutorial.
The problem I’m having is that I do development on my local box, push code to a dev environment for testing, further on to a staging environment for final UAT and then on to prod. Through these different environments my field_group IDs (and slugs) can change. There must be a better way to specify the field groups. A field you can set uniquely on the field group when it’s created would be ideal. I tried editing the slug field, but it just gets overwritten with a system generated one. This feels like a deficiency in ACF.
Anybody have a solution for this?
Thanks,
Dana
If you look at the docs https://www.advancedcustomfields.com/resources/acf_form/#parameters the only supported values for fields and groups are the following:
/* (array) An array of field group IDs/keys to override the fields displayed in this form */
'field_groups' => false,
/* (array) An array of field IDs/keys to override the fields displayed in this form */
'fields' => false,
Actually, I found a way that will work great in my situation.
register_post_type() to the rescue.
$args = array (
‘labels’ =>
array (
‘name’ => ‘Mentors’,
‘singular_name’ => ‘Mentor’,
…
),
‘description’ => ‘Users volunteering to mentor others.’,
‘public’ => true,
…
‘rewrite’ =>
array (
‘slug’ => ‘mentors’,
‘with_front’ => true,
),
…
‘taxonomies’ =>
array (
),
);
register_post_type(“mentor”,$args);
Then in the Field Group:
Show this field group if: Post Type — is equal to — Mentor (from label singular_name)
Probably going to have to work on the taxonomies, but one step at a time.
BTW. I tried
Show this field group if: Page Template — is equal to — Call for Mentors Form (my page template name), but for whatever reason that didn’t work.
Forgot to mention in my template in the afc_form argument array I specify the post_type
‘new_post’ => array(
‘post_type’ => ‘mentor’,
‘post_status’ => ‘pending’,
‘post_title’ => ‘New Message’