Home › Forums › Backend Issues (wp-admin) › How to use ACF in a plugins admin page › Reply To: How to use ACF in a plugins admin page
@souvarian and @elliot: thanks for the input.
It needs some more thorough testing but I think I have it working now. Thanks to you both.
As I have registered my field_groups using the ACF-UI, I am not using the register_field_group function. That way I don’t have the problem with the location.
How I use these funtions:
– on hook ‘admin_init’ I call
/* hooked on admin_init */
public function add_afc_head() {
if (in_array(hbd_functions::get_page_by_url(), hbd_settings::$plugin_page_names)) {
hbd_debug::write_log('acf_form_head called');
acf_form_head();
}
}
– on hook ‘admin_menu’ I build by menu using add_menu_page();
– In the callback of that function I do these actions:
do_action(‘acf/input/admin_head’);
do_action(‘acf/input/admin_enqueue_scripts’);
– Then render my page.
– In my page I call acf_form like this:
$options = array(
'post_id' => hbd_settings::AFC_POST_TOKEN, // post to save to
'field_groups' => array(hbd_settings::AFC_FORM_ID), // field group id
'form' => true,
'form_attributes' => array(
'id' => 'design-fotos',
'action' => '',
'method' => 'post'
),
'return' => add_query_arg( 'updated', 'true', (get_admin_url() . 'admin.php?page=s-advanced-search') ), // return url
'submit_value' => 'Opslaan',
'updated_message' => 'Afbeeldingvelden opgeslagen',
);
acf_form($options);
I hope this solves your question as well souverian. If it doesn’t open a new thread and let me know. I’ll look into it as well.
As long as further debugging does not surface any issues; topic solved!
Thanks for the input,
sKuijers
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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.