Home › Forums › Front-end Issues › Frontend form Edit Post link › Reply To: Frontend form Edit Post link
I followed what James was saying and used the $_GET method. Here’s how I made it work, hopefully it will help someone:
(I’m assuming you know how to create WordPress page templates, and know how to create ACF submit forms)
1. Add a button on your single.php that sends the post id with $_GET to a page that we will create next:
global $post;
$postID = $post->ID; ?>
<a href="./page-with-form/?post=<?php echo $postID; ?>">Edit Post Button</a>
2. Create a page template with the ACF form in it. This page from the ACF documentation has an example on how to edit a specific post with a form. You’ll just have to set the post id dynamically in this case. This is what my form looks like:
<?php acf_form(array(
'post_id' => $post_id, //Variable that you'll get from the URL
'post_title' => true,
'post_content' => true,
'fields' => array('_thumbnail_id', 'ask_for_donations'), //The name of the custom fields I want to show on the form
'submit_value' => 'Update Content',
'return' => '%post_url%' //Returns to the original post
)); ?>
3. To read the post id that has been passed on the URL (will look like: ?post=number) add the following line on the page template somewhere before the form starts:
$post_id = $_GET["post"];
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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
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.