Support

Account

Forum Replies Created

  • Awesome thanks heaps Elliot.

    Managed to get it happening code below for anyone else:

    In my template file

    <?php 
      $args = array(
       'post_id' => 'new',
       'field_groups' => array(56,127),
       'html_before_fields' => '<input type="hidden" name="the_post_type" value="this is where you pop the post type or just post"/>'
    );
    
    acf_form( $args ); 
     
    ?> 

    and in the functions.php

    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'  => 'publish' ,
            'post_title'  => $_POST["fields"]['field_529c0886500bd'],
            'post_type'  => $_POST['the_post_type']
        );  
     
         $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;
        
       
    }
  • 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?

  • 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 cool thanks Elliot, I’ve some more examples of the acf/load_field filter in action so will figure it out.

    Thanks for your help answering my question really appreciate the time,

    Mike

  • Cool thanks Elliot, so do I just drop this bit of code into my functions.php file in my theme? Do I need to write any of the code from the acf/load_field filter resources link?

    Is there a tweak to the code you have above that can still make the fields visible/editable by admin. So:

    
    // compare and completely remove field if this user is not meant to see it! Unless they are admin, then always show it
    	if( $current_user_name != $user {but do show if the user is admin} )
    	{
    		$field = null;
    	}
    	
    	
    	return $field;
    }
    

    Really appreciate your help!!!

  • Thanks Elliot,

    Does this mean everytime I add a new user though and I want them to access a custom field all of their own I’ll need to create a new location rule or with the above mentioned tutorial will it enable me to match current logged in user to anyone from the user list?

    Sorry to take up your time. I’m making a rostering page that employees can login and accept decline jobs but want them to yes/no only their custom field and not have access to everyones. Is this method I’m mentioning not the best. If using the front end edit plugin I know I could hide the custom fields with jquery and only show the logged in user by matching the username with the class that is applied to the wrapper of the radio buttons.

    Mike

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