Home › Forums › Front-end Issues › Frontend form submit button not working › Reply To: Frontend form submit button not working
from my themes/evolve/functions.php
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']['post_title'];
$content = $_POST['fields']['post_content'];
// Create a new post
$post = array(
'post_status' => 'publish',
'post_type' => 'prueba',
'post_title' => $title,
'post_content' => $content
);
// insert the post
$post_id = wp_insert_post( $post );
// return the new ID
return $post_id;
}
prueba is the name of my custom post type
from my single-custom.php
<?php acf_form_head(); ?>
<?php get_header(); ?>
<div id="primary">
<div id="content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php acf_form(array(
'post_id' => 'new_post',
'field_groups' => array( 577 )); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
the name of the field for the title is post_title and for the content post_content, only tried this for if was a problem of compatibility with other fields, but anyway this not working anyway, how I said, it shows the form but the button doesn’t do anything.
577 is the ID of my ACF group fields.
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.