Support

Account

Home Forums Front-end Issues Controlling fields order and labels in acf_form

Solved

Controlling fields order and labels in acf_form

  • I am using ACF Pro (version 5.7.7).

    I have a custom post type with custom fields. I am using acf_form to create a frontend page for adding new posts and editing existing posts of this custom type.

    I would like to use the default wordpress post content field and have a couple of questions:

    1. I would like to change the order of fields shown by ac_form on the frontend page and place the default content field in between the custom fields. Is there any way to control the exact order of fields shown by acf_form in such a way ?
    2. Is it possible to change the labels of the fields shown by acf_form on the frontend page ?

  • 1) When using the build in WP title and content fields there isn’t any way to alter the order of them. To do this you would have to create content and title fields in ACF and then transfer the content of them to the standard fields on acf/save_post by getting the values from acf and updating the post.

    
    add_action('acf/save_post', 'my_update_post', 20);
    function my_update_post($post_id) {
      $post = array(
        'ID' => $post_id,
        'post_content' => get_field('my_alt_content_field', $post_id),
        'post_title' => get_field('my_alt_title_field', $post_id)
      );
      // remove this filter to prevent infinite loop
      remove_filter('acf/save_post', 'my_update_post', 20);
      // update post
      wp_update_post($post);
      // re-add filter
      add_action('acf/save_post', 'my_update_post', 20);
    }
    

    2) Yes, acf/prepare_field can be used to do this, your filter would look something like

    
    add_filter('acf/prepare_field/key=field_123456', 'alter_label_on_field_a');
    function alter_label_on_field_a{$field) {
      if (is_admin()) {
        // no change in admin
        return $field;
      }
      $field['label'] = 'new label for front end form';
      return $field;
    }
    
  • Thank you for the reply.

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

The topic ‘Controlling fields order and labels in acf_form’ is closed to new replies.