Home Forums Front-end Issues Need help on editing custom fields on the front end


Need help on editing custom fields on the front end

  • Hi,

    I need help on updating my custom fields on the front end. I’m trying to find a way to have what’s inside a custom field called ‘iad_author’ to be shown in the input and then have the user can edit the text and then save it back to the custom field.

    The code I have so far:

    <?php acf_form_head(); ?>
    <?php get_header(); ?>
    <?php get_header('single'); ?>
    <?php $title= the_field('iaf_author');?>
    			<?php /* The loop */ ?>
    			<?php while ( have_posts() ) : the_post(); ?>
    				<h1><?php the_title(); ?></h1>
    				<?php the_content(); ?>
    				<p>My custom field: <?php the_field('iaf_author'); ?></p>
    				<input type="text" name="title" value="$title">
    <?php update_field( 'iaf_author', $title, $post->ID );?>
    				<?php acf_form(); ?>
    			<?php endwhile; ?>
    <?php get_footer(); ?>

    What the code does now is the input field has ‘$title’ in the field and the data in that custom field is removed when saved.

    Thanks for helping.

  • Hi @gschultz

    To store variables from ACF, you need to make use of the get_field() function on this line:

    $title= the_field('iaf_author');

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

You must be logged in to reply to this topic.