Hi, I am having an issue with live edit. I have followed the instructions but can’t get it to work. How would I add a live edit function to each element in the below loop? The loop contains a heading, some paragraph text and an option to choose the column width. I want all these to be editable in the fontend. The other alternative is to use ”acf_form()” But I would need to assign an individual form to each element is that possible? Cheers
<?php // check if the flexible content field has rows of data
if( have_rows('add_content') ):
// loop through the rows of data
while ( have_rows('add_content') ) : the_row(); ?>
<?php
if( get_row_layout() == 'heading' ):?>
<h1 class="content-heading"><?php the_sub_field('heading');?></h1>
<?php
elseif( get_row_layout() == 'paragraph_text' ): ?>
<div class="<?php the_sub_field('choose_column_width');?>-col">
<?php the_sub_field('paragraph_text');?></div>
<?php ;
endif;
endwhile;
else :
// no layouts found
endif;
?>
Hi @eckul,
Thanks for the post.
It would be a lot easier if you could make use of the acf_form() function and pass the flexible content field key to the ‘fields’ argument of the form.
You will only need to pass the acf_form_head() function at the top of your template to handle the processing of the form data and the acf_form() function within the posts loop.
To create a new post, the code would look like so:
<?php acf_form_head(); ?>
<?php get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php acf_form(array(
'post_id' => 'new_post',
'fields' => array('field_key'),
'new_post' => array(
'post_type' => 'event',
'post_status' => 'publish'
),
'submit_value' => 'Create a new event'
)); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>