Home › Forums › Front-end Issues › Posting from front-end to custom post type – not working
I have set up a custom post type, ‘Files’ and have created custom fields which has the following fields:
Title, File upload, Thumbnail upload, Category.
I have used the following code to get this displaying on a page on the front end:
<?php
acf_form_head();
get_header(); ?>
<div id="primary">
<div id="content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php
acf_form(array(
'id' => 'File / Media Upload Form',
'post_id' => 'new_post',
'post_title' => true,
'post_content' => true,
'submit_value' => 'Add file',
'new_post' => array(
'post_type' => 'files',
'post_status' => 'publish'
)
));
?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
The custom post type also shows up in the back end automatically and if I use this to post, it works but the form on the front end does not work. It submits without any errors but nothing is posted in ‘Files’ or in the POST table in the database. The images are submitted to the media library.
Can someone please help me troubleshoot?
Many thanks
That’s weird. I’ve just tested your form code and it was working great. Maybe there’s a function in your theme or plugins that caused this issue. Could you please try to reproduce the issue on one of the WordPress’ stock themes (like Twenty Sixteen) with other plugins deactivated? If it disappears, then you can activate the theme and plugins one by one to see which one causes the issue.
Thanks 🙂
I realised I was reading the documentation for the wrong version! Its very confusing and should be made clearer. As far as I can see V5 isn’t even available yet so why does the documentation default to v5?
Version 5 is another name for ACF PRO and version 4 is the free version. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/acf-pro/. If you want to use ACF version 5, please check this page out: http://www.advancedcustomfields.com/pro.
Thanks 🙂
You must be logged in to reply to this topic.
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!
Plugin boilerplates can do some of the heavy lifting during initial development. We look at four options to speed up your plugin creation. https://t.co/ZtMsdBxAHw
— Advanced Custom Fields (@wp_acf) June 5, 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.