Support

Account

Home Forums ACF PRO Options page in front-end

Solved

Options page in front-end

  • I know you can use acf_form for displaying the generic post form in the front end of a WordPress site. Can I use it or something similar to display an options page in the front end?

    I’m working on a system where the wp-admin section will not be visible to anyone except the administration, but options pages should be available to editors and other lower roles in the frontend.

    I’m using ACFPRO as a theme included plugin. Latest WP installed.

  • Right now I’ve got the following working:

    1. Read all field groups using acf_local()->get_field_groups().
    2. Filter out all that are not in options pages as per the location matching rules.
    3. Get fields for all groups that are matched using acf_get_local_fields( $fieldgroup_key ).
    4. Read group keys and field keys.
    5. Output HTML based on group and fields as in foreach ( $groups as $fields ) : foreach ( $fields as $field_key => $field_data ) : printf( ... ); endforeach; endforeach;
    6. Said outputted fields are sent using standard HTML form element to the same page template (action="").
    7. Validation, referers, nonces, etc.
    8. Use the POST data to read field keys and update the database values from sanitized $_POST using update_field( $field_key, $value, 'options' ).

    Currently this works fine for non-JS infused fields, such as selects, text fields and so on. I’m working on getting the color picker working, which in the end should use a hidden text field anyway.

    Is there a more correct way to do this or should I wrap this into a plugin of sorts?

  • Thanks for posting this. This is exactly what I’m looking for. Would you mind posting your entire form code? I’m having trouble following exactly what you did.

    Thanks

  • I’m afraid I can’t find the exact code I used for my previous post. 🙁

    Additionally I’m not sure whether the method of doing this has changed between ACF4 and ACFPRO.

  • This can be done using acf_form() http://www.advancedcustomfields.com/resources/acf_form/

    Create the options page and the field groups you want on it and then for the front end form use options as the post_id value and list the field groups that you want to show.

    
    $args = array(
      'post_id' => 'options',
      'field_groups' => array(3199) // this is the ID of the field group
    );
    acf_form($args);
    

    Follow the rest of the instructions for using acf_form()

  • Sorry, ignore me – realise that you have to explicitly call the fields / field groups rather than the whole form…

    >>>

    Hi @hube2

    I’m trying to do this but just nothing on the front end apart from my submit button.

    Code:

    
    <?php acf_form(array(
    	'post_id' => 'options',
    	'submit_value'	=> 'Update settings',
    	'return' => add_query_arg( 'updated', 'true', home_url() . '/settings' ),
    )); ?>
    

    Any idea?

    cheers

    Mike

  • This worked for me. Of course call ACF header correctly before

    
    				<?php acf_form(array(
    					'post_id'			=> 'options',
    					'post_title' 	=> false,
    					'submit_value'=> 'Update',
    					'field_groups'=> [643],
    
    				)); ?>
    

    use your field group ID-s

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

The topic ‘Options page in front-end’ is closed to new replies.