Home › Forums › Pre-purchase Questions › Can ACF do this? (with Social Article) › Reply To: Can ACF do this? (with Social Article)
Hiya @topy
In short, yes everything you describe is doable.
1) You can create an ACF form and then embed this form onto a page and tell the form that it needs to create a new page, post or custom post type. You can also wrap this code into a check to see if the user is logged in so that only logged in users can access this form.
2) You can set the form to always create ‘draft’ posts by default. Or alternatively, you can make it a changeable field and combine it with a hook to actually make the post draft or published. I’ve actually recently done this myself. You would have a field in your ACF form called ‘status’. Then you create a hook that is triggered when this form is submitted. It would get the value of that field, and use it to set the status of the post.
3) The same code that renders the form onto the page from item 1 above, can be used but with a different parameter that edits a post instead of creating a new one.
For example, on your page where you have the form embedded, right at the top you’d have:
/**
* Is something being edited?
* Is the user trying to do this, the author of the post being edited, or an admin?
* If not, redirect back to home
*/
if (isset($_GET['edit'])) {
// get the post being edited
$thispost = get_post($_GET['edit']);
if (USERID == $thispost->post_author || is_administator()) {
$new_post = $_GET['edit'];
} else {
header('Location: '.get_bloginfo('home'));
exit;
}
} else {
$new_post = 'new_post';
}
So if your post create page is website.com/new-post
then to edit a post using that same form, you’d have website.com/new-post?edit=23
and then you’d be editing post 23.
And to actually embed the form that uses the logic above, you’d have:
$formoptions = array(
'post_title' => true,
'post_content' => false,
'post_id' => $new_post,
'field_groups' => array(256),
'submit_value' => 'Publish',
'return' => get_permalink(142),
'uploader' => 'wp'
);
acf_form($formoptions);
Hope this answers your questions and helps you confirm the purchase of ACF. It definitely is an incredible piece of software and worth absolutely every penny 🙂
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!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 8, 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.