Create Custom Post Type from front end template using Advanced Custom Fields

I want a form on the front end for creating a Custom Post Type using the Advanced Custom Fields plugin.

I’m using code from the tutorial Create A Front End Form combined with code I found on Stack Overflow that defines the $options for <?php acf_form(); ?>.

Read More

The code I have so far is:

<?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
            $options = array(
                'post_id' => $post->ID, // post id to get field groups from and save data to
                'field_groups' => array(), // this will find the field groups for this post (post ID's of the acf post objects)
                'form' => true, // set this to false to prevent the <form> tag from being created
                'form_attributes' => array( // attributes will be added to the form element
                    'id' => 'post',
                    'class' => '',
                    'action' => 'submit',
                    'method' => 'post',
                ),
                'return' => add_query_arg( 'updated', 'true', get_permalink() ), // return url
                'html_before_fields' => '', // html inside form before fields
                'html_after_fields' => '', // html inside form after fields
                'submit_value' => 'Submit', // value for submit field
                'updated_message' => 'Post updated.', // default updated message. Can be false to show no message 
            );
            acf_form( $options );
            ?>

        <?php endwhile; ?>
    </div><!-- #content -->
</div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

I’m not sure how to make this work:

  • How do I specify the post ID?
  • How/where do I specify the connection to the Custom Post Type and the custom fields I want to show?

Can you please tell me where in the code can I get specific information like my field IDs, etc?

Related posts

Leave a Reply

1 comment