0

I have create edit ACF form in front end and i wrote that post title can be edit also by that form.

but when I change post title field, my permalink does not change based on title.

<?php 
                if ( ( is_user_logged_in()  ) ) {
                    echo "<div class='acf-edit-post'>";
                    acf_form_head();
                        acf_form (array(
                            //'post_id'            => 401, // Get the post ID
                            'post_title'         => get_the_title(),
                            'field_groups'       => array(7), // Create post field group ID(s)
                            'form'               => true,
                            'return'             => '%post_url%',
                            'html_before_fields' => '',
                            'html_after_fields'  => '',
                            'submit_value'       => 'Save Changes',
                            'updated_message'    => __("Post updated", 'acf')
                        ));
                    echo "</div>";
                }
            ?>
  • use acf_form_head() before get_header();. For more reference check this link : advancedcustomfields.com/resources/create-a-front-end-form – Piyush Rawat Nov 16 '17 at 4:37
  • thank you but I have tried that, it still the same – Diana Rider Nov 16 '17 at 5:08
  • turn wp_debug to true in wp-config.php and see if there's any error – Piyush Rawat Nov 16 '17 at 5:09
  • i have try that also but does not print any thing error – Diana Rider Nov 16 '17 at 5:45
  • whic template file is this code located in? The post_id has to be provided if its not inside the loop – Piyush Rawat Nov 16 '17 at 6:34
2

have you found an answer to that yet? I recently needed to redirect users to a custom made page that hosts an ACF form and loads the values of that particular post into the form. You are going to need 2 things in order to make that work:

  1. In your functions.php, redirect non-admin users to your edit page (which you'll create at step 2) in the frontend. To do that add:

    add_filter( 'get_edit_post_link', 'custom_edit_post_link', 10, 1 );
    
    function custom_edit_post_link( $url ) {
        # If user is admin go to Dashboard
        if ( current_user_can('manage_options') ) {
              return $url;
        }
        # else redirect the user to my edit entry page & send the post_id on URL
        return esc_url( add_query_arg( 'post_id', get_the_ID(), home_url('/entry-edit/') ) ); //where entry-edit is my page's slug
    }
    

https://github.com/Alina-chan/acf_ideas/blob/master/front-end%20post%20edit%20with%20acf%20form/functions.php

  1. Now create a custom template for your page and name it {name}-edit.php. In there you should place your ACF form. Take a look at mine here: https://github.com/Alina-chan/acf_ideas/blob/master/front-end%20post%20edit%20with%20acf%20form/post-edit.php

By getting the post_id from your URI, you can use it inside your template and load the post's values in your ACF form.

Hope it helped you a bit!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.