Home Forums General Issues Publishing to custom fields from front end?


Publishing to custom fields from front end?

  • I have a simple demo form that will publish to my custom post type from the front end (it’s on a local offline server). However, it only works with the default wordpress fields (title and content), at the moment.

    Does anyone know how to add a custom field from ACF to this form? I’ve searched Google and having trouble finding anything.

    Thanks in advance,
    Michael Newsome

  • Can you give more details about what you mean by “publish to my custom post type from the front end”? Are you accepting input from the front end to create custom posts?

    Can you post the code that is generating your form?

    What type of fields do you want to add to the form and what fields are already on the form?

  • It’s a custom post type called Events. Right now, it’s just a textbox called Test Field. For now, I need to be able to put textbox and textarea on the front end (but would like to maybe put a repeater there, if possible, but I’m not sure that it is).

    This is above the header:

    if ( isset( $_POST['submitted'] ) && isset( $_POST['post_nonce_field'] ) && wp_verify_nonce( $_POST['post_nonce_field'], 'post_nonce' ) ) {
        if ( trim( $_POST['postTitle'] ) === '' ) {
            $postTitleError = 'Please enter a title.';
            $hasError = true;
        $post_information = array(
            'post_title' => wp_strip_all_tags( $_POST['postTitle'] ),
            'post_content' => $_POST['postContent'],
            'post_type' => 'events',
            'post_status' => 'publish'
        wp_insert_post( $post_information );

    And this is the actual form:

    <form action="" id="primaryPostForm" method="POST">
            <label for="postTitle"><?php _e('Post Title:', 'framework') ?></label>
            <input type="text" name="postTitle" id="postTitle" class="required" value="<?php if ( isset( $_POST['postTitle'] ) ) echo $_POST['postTitle']; ?>" />
            <label for="postContent"><?php _e('Post Content:', 'framework') ?></label>
            <textarea name="postContent" id="postContent" rows="8" cols="30" class="required"><?php if ( isset( $_POST['postContent'] ) ) { if ( function_exists( 'stripslashes' ) ) { echo stripslashes( $_POST['postContent'] ); } else { echo $_POST['postContent']; } } ?></textarea>
            <input type="hidden" name="submitted" id="submitted" value="true" />
            <button type="submit"><?php _e('Add Post', 'framework') ?></button>
            <?php wp_nonce_field( 'post_nonce', 'post_nonce_field' ); ?>
    <?php if ( $postTitleError != '' ) { ?>
        <span class="error"><?php echo $postTitleError; ?></span>
        <div class="clearfix"></div>
    <?php } ?>

    When I post to the Events post type from the front end, I just need to be able to put data in these custom fields, also.

  • Ahh, I see what you’re trying to do. I’ve never done it, and can’t answer your question. But I did find something that might steer you in the right direction.

    This looks like a good start:

    Then this answers the first question I had looking at the example:

    As far as the repeater goes, it’s pretty awesome and it took me a bit to wrap my head around at first. It’s basically a group of fields that a user can keep adding new instances of.

    I hope this helps and good luck.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Publishing to custom fields from front end?’ is closed to new replies.