Home › Forums › Front-end Issues › Form to post:
I’ve spent the last two days trying to build “form to post” mechanism for my music website, but am not getting anywhere, so I’m posting it here.
Basically, I created a custom form with ACF Pro (v. 5.4.7) that includes various album-related information (name, artist, description, cover image, year published, length, rating).
I built an add-music.php page that is supposed to contain a form to enter a new album and have it posted to the site, and a single-music.php for displaying those posts.
I also use the Custom Post Types UI plugin for creating the “music” post types.
The closest I’ve come to making it work is this:
<?php
acf_form_head();
[...]
$arguments = array(
'field_groups' => array(123),
'return' => home_url('thanks'),
'post_id' => 'new_post',
'post_title' => true,
'new_post' => array(
'post_status' => 'publish',
'post_type' => 'music',
'post_title' => the_field('albumtitle')
),
'submit_value' => 'Add Album'
);
acf_form($arguments);
The problem is that this doesn’t really do what I thought it would do.
Instead of using my ACF-created ‘albumtitle’ field that is part of form 123, it adds a completely new and unrelated “title” field to the top of my form.
The title entered there is then actually used as the title of the new post, but the the field from my form is ignored. If I change the code to not display that field but only the actual form field the WP title is not adjusted.
I could remove my own title field of course, but then I still wouldn’t know how to access all the other values.
Thanks for your help!
If you want to use and ACF field for the post title then you need to create an acf/save_post or acf/update_value filter that will get the value from the field and update the post title. There are some examples of how others have done this on the forum, here are some links.
The topic ‘Form to post:’ is closed to new replies.
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.