Support

Account

Home Forums Front-end Issues Posting from front-end to custom post type – not working

Solved

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

  • Hi @leanne-oleary

    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?

  • Hi @leanne-oleary

    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 🙂

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

The topic ‘Posting from front-end to custom post type – not working’ is closed to new replies.