Support

Account

Home Forums General Issues Live Edit labels empty after creating a post using acf_form

Solved

Live Edit labels empty after creating a post using acf_form

  • Hi Elliot,

    When I create a post from the front-end following http://www.advancedcustomfields.com/resources/tutorials/using-acf_form-to-create-a-new-post/ the new post is saved perfectly. I then go to edit it using Live Edit but my live edit panel is empty with no labels as in this picture:

    http://cl.ly/image/2e133P212V05

    In my functions file:

    function my_pre_save_post( $post_id )
    {
        // check if this is to be a new post
        if( $post_id != 'new' )
        {
            return $post_id;
        }
     
        // Create a new post
        $post = array(
            'post_status'  => 'published' ,
            'post_title'  => $_POST["fields"]['field_529c0886500bd'],
            'post_type'  => 'post' ,
        );  
     
       $post_id = wp_insert_post( $post ); // Insert the post
        do_action( 'acf/save_post' , $post_id ); // Save the fields to the post
        wp_redirect( add_query_arg( 'updated', 'true', get_permalink( $post_id ) ) ); exit; // Redirect to the new post
        return $post_id;
    }
     
    add_filter('acf/pre_save_post' , 'my_pre_save_post' );
    

    In my template:

    <?php 
     
    /**
     * Template Name: Create a Post
     */
     
    acf_form_head();
     
    get_header(); 
     
    the_post();  
     
    ?>
    </header>
    	
    <div id="content" class="row single-col with-sidebar">
    
    	<article>
    	
    	<section>
    	<?php the_post(); ?>
    	
    	<?php
    		
    		if ( is_user_logged_in() ) { ?>
    		
    			<h1 class="h2">Create a Profile</h1>
    			<?php the_field('logged_in'); ?>
    			
    			<?php 
     
    			$args = array(
    				'post_id' => 'new',
    				'field_groups' => array('127')
    			);
     
    			acf_form( $args ); 
     
    			?> 
    			
    			</section>
    			
    			<aside>
    				<h2>What would you like to do?</h2>
    				<?php get_sidebar('useful_links'); ?>
    			</aside>
    		
    		
    	<?php 
        	
        	} else { ?>
        	
        		<?php the_content(); ?>
        		
        		</section>
        		
        		<aside>
        		<h2>Login to <?php the_title(); ?></h2>
    			<?php echo do_shortcode('[theme-my-login instance="1"]'); ?>
    			</aside>
        		
        	
        <?php } ?>
    		
    	</article>
     
    <?php get_footer(); ?>

    However if I go into the backend of site and update the post (don’t need to add any content just click update) and then go to the post the click the live edit all the fields are there complete as in this picture:

    http://cl.ly/image/1S2M1Y3e231o

    The goal:

    User logs in, creates a post via the acf_form, they get redirected to that post where they can then live edit it further with more details. It’s just at the moment when they click live edit all the labels and form elements are empty.

  • And here is my single.php:

    <?php get_header(); ?>	
    </header>
    	
    <div id="content" class="row artist single-col">
    <?php the_post(); ?>
    	<article <?php if(function_exists("live_edit")){live_edit('post_title,short_blurb,photo, instrument_or_service, facebook_link, twitter_link, email_address, website_address, soundcloud_link, bandcamp_link, itunes_link, youtube_link, vimeo_link, audio_track_or_playlist, single_bandcamp_audio_tracks, youtube_videos, vimeo_videos, another_photo, full_bio'); }?>>
    	
    	
    		
    	<?php
    	$attachment_id = get_field('photo');
    	$size = "medium"; // (thumbnail, medium, large, full or custom size)
     
    	$image = wp_get_attachment_image_src( $attachment_id, $size );
    
    	?>
    	
    	<img class="artist alignleft" src="<?php echo $image[0]; ?>" />	
    		<h1 class="h2"><?php the_title(); ?></h1>
    				
    		
    
    		<?php
    			$tags = get_field('instrument_or_service');
    			if( $tags ): 
    				echo '<p>';
    				foreach( $tags as $tag): 
    			
    				setup_postdata($tag);
    	   
    	   			echo '<a href="/' . $tag->taxonomy . '/' . $tag->slug . '">' . $tag->name . '</a>, ';		
    	   			endforeach; 
    	   		endif; wp_reset_postdata();
    		?>
    		</p>
    		<p><?php the_field('short_blurb'); ?></p>
    			
    		<div class="social-links">
    			
    			<?php if( get_field('facebook_link') ) { ?>
    			
    				<a title="Facebook" href="<?php the_field('facebook_link'); ?>" class="facebook-link">Facebook</a>
    				
    			<?php } ?>
    			
    			<?php if( get_field('twitter_link') ) { ?>
    			
    				<a title="Twitter" href="<?php the_field('twitter_link'); ?>" class="twitter">Twitter</a>
    				
    			<?php } ?>
    			
    			<?php if( get_field('email_address') ) { ?>
    			
    				<a title="Email" href="mailto:<?php the_field('email_address'); ?>" class="email">Email</a>
    				
    			<?php } ?>
    			
    			<?php if( get_field('website_address') ) { ?>
    			
    				<a title="Website" href="<?php the_field('website_address'); ?>" class="website">Website</a>
    				
    			<?php } ?>
    		
    			<?php if( get_field('soundcloud_link') ) { ?>
    			
    				<a title="Soundcloud" href="<?php the_field('soundcloud_link'); ?>" class="soundcloud">Soundcloud</a>
    				
    			<?php } ?>	
    			
    			<?php if( get_field('bandcamp_link') ) { ?>
    			
    				<a title="Bandcamp" href="<?php the_field('bandcamp_link'); ?>" class="bandcamp">Bandcamp</a>
    				
    			<?php } ?>
    			
    			<?php if( get_field('itunes_link') ) { ?>
    			
    				<a title="iTunes" href="<?php the_field('itunes_link'); ?>" class="itunes">iTunes</a>
    				
    			<?php } ?>
    				
    			<?php if( get_field('youtube_link') ) { ?>
    			
    				<a title="YouTube" href="<?php the_field('youtube_link'); ?>" class="youtube">YouTube</a>
    				
    			<?php } ?>
    			
    			<?php if( get_field('vimeo_link') ) { ?>
    			
    				<a title="Vimeo" href="<?php the_field('vimeo_link'); ?>" class="vimeo">Vimeo</a>
    				
    			<?php } ?>
    			
    			
    			
    			
    			
    			
    		</div>
    		
    		<div class="controls">
    			<a href="#listen">Listen</a>
    			<a href="#watch">Watch</a>
    			<a href="#read">Read</a>
    		</div>
    		
    	<section id="listen">
    	
    		<h2>Listen</h2>
    		
    		<div class="row">
    		
    			<?php if( get_field('audio_track_or_playlist') ): ?>
    							
    				<?php while( has_sub_field('audio_track_or_playlist') ): ?>
    					
    					<?php the_sub_field('track_id_number_soundcloud'); ?>
    						 					
    				<?php endwhile; ?>
    			<?php endif; ?>
    			
    			<?php if( get_field('single_bandcamp_audio_tracks') ): ?>
    							
    				<?php while( has_sub_field('single_bandcamp_audio_tracks') ): ?>
    					
    					
    					<?php the_sub_field('track_id_number_bandcamp'); ?>
    					
    						 					
    				<?php endwhile; ?>
    			<?php endif; ?>
    					
    		</div>
    		
    				
    	<h2>Releases/Appears On</h2>	
    	<section class="thumb-list">
    	
    		<div>
    			<a class="thumb" href="<?php the_permalink(); ?>"><img src="http://placehold.it/150/150"></a>
    		<p>
    			<a href="">Release Name</a><br />
    			<em>Artist Name</em><br />
    			<span class="date">the date</span>
    		</p>	</div>	
    	
    	<div>
    			<a class="thumb" href="<?php the_permalink(); ?>"><img src="http://placehold.it/150/150"></a>
    		<p>
    			<a href="">Release Name</a><br />
    			<em>Artist Name</em><br />
    			<span class="date">the date</span>
    		</p>
    	</div>	
    	
    	<div>
    			<a class="thumb" href="<?php the_permalink(); ?>"><img src="http://placehold.it/150/150"></a>
    		<p>
    			<a href="">Release Name</a><br />
    			<em>Artist Name</em><br />
    			<span class="date">the date</span>
    		</p>
    	</div>	
    	
    	</section>
    
    	
    	</section>	
    		
    	<section id="watch">
    	<h2>Watch</h2>
    		
    		<?php if( get_field('youtube_videos') ): ?>
    							
    			<?php while( has_sub_field('youtube_videos') ): ?>
    			
    				<div class="video">
    					
    					<?php $code = get_sub_field('video_link'); ?>
    				
    					<?php echo do_shortcode('[youtube id="'.$code.'"]'); ?>
    					
    				</div>
    
    			<?php endwhile; ?>
    		<?php endif; ?>
    		
    		<?php if( get_field('vimeo_videos') ): ?>
    							
    			<?php while( has_sub_field('vimeo_videos') ): ?>
    			
    				<div class="video">
    					
    					<?php $code = get_sub_field('video_link'); ?>
    				
    					<?php echo do_shortcode('[vimeo id="'.$code.'"]'); ?>
    					
    				</div>
    
    			<?php endwhile; ?>
    		<?php endif; ?>
    		
    				
    	</section>	
    	
    	<section id="read">
    	<h2>Read</h2>
    	<?php
    		if( get_field('another_photo') ){
    	
    		
    	$attachment_id = get_field('another_photo');
    	$size = "medium"; // (thumbnail, medium, large, full or custom size)
     
    	$image = wp_get_attachment_image_src( $attachment_id, $size );
    
    	?>
    	
    	<img class="artist alignleft" src="<?php echo $image[0]; ?>" />
    		<?php } ?>
    	<?php the_field('full_bio'); ?>
    
    	</section>
    	
    
    	</article>
    <?php get_footer(); ?>
  • OK I have figured it out. In my create a post form I was bringing in a custom field set that only had one field but on the live edit page I had another set. By adding both sets to the form and creating the post, the live edit shows the acf’s correctly. Only bugger is I’d really like to hide the main set from the create a post form as the acf css buggers up the look so I was keen to roll with one act set.

    The form outputs:

    <div id=”acf_56″ class=”postbox acf_postbox no_box”>…</div>
    <div id=”acf_127″ class=”postbox acf_postbox no_box”>…</div>

    so I can hide #acf_56 with CSS, is this the best workaround?

  • Hi @planktonwebdesign

    Yep, simple hide it with CSS, that should work fine for your customers.

    Cheers
    E

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

The topic ‘Live Edit labels empty after creating a post using acf_form’ is closed to new replies.