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:
acf_get_local_fields( $fieldgroup_key ).
foreach ( $groups as $fields ) : foreach ( $fields as $field_key => $field_data ) : printf( ... ); endforeach; endforeach;
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?
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
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…
I’m trying to do this but just nothing on the front end apart from my submit button.
<?php acf_form(array( 'post_id' => 'options', 'submit_value' => 'Update settings', 'return' => add_query_arg( 'updated', 'true', home_url() . '/settings' ), )); ?>
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.